Whats a more object oriented way to execute a python script
$begingroup$
The following code cd's into the scrape folder, and enters the command "scrapy crawl yellow". It works well, however i want to make this more object oriented looking, utilizing something like
if__name__== "__main__"
not sure how to implement this kind of code. Ultimately i want this to be an executable which is why im trying to make it more object oriented.
App.py
import os
import subprocess
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
python
New contributor
$endgroup$
add a comment |
$begingroup$
The following code cd's into the scrape folder, and enters the command "scrapy crawl yellow". It works well, however i want to make this more object oriented looking, utilizing something like
if__name__== "__main__"
not sure how to implement this kind of code. Ultimately i want this to be an executable which is why im trying to make it more object oriented.
App.py
import os
import subprocess
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
python
New contributor
$endgroup$
1
$begingroup$
This code makes no sense. How couldourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.
$endgroup$
– 200_success
1 hour ago
add a comment |
$begingroup$
The following code cd's into the scrape folder, and enters the command "scrapy crawl yellow". It works well, however i want to make this more object oriented looking, utilizing something like
if__name__== "__main__"
not sure how to implement this kind of code. Ultimately i want this to be an executable which is why im trying to make it more object oriented.
App.py
import os
import subprocess
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
python
New contributor
$endgroup$
The following code cd's into the scrape folder, and enters the command "scrapy crawl yellow". It works well, however i want to make this more object oriented looking, utilizing something like
if__name__== "__main__"
not sure how to implement this kind of code. Ultimately i want this to be an executable which is why im trying to make it more object oriented.
App.py
import os
import subprocess
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
python
python
New contributor
New contributor
New contributor
asked 4 hours ago
randalrandal
11
11
New contributor
New contributor
1
$begingroup$
This code makes no sense. How couldourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.
$endgroup$
– 200_success
1 hour ago
add a comment |
1
$begingroup$
This code makes no sense. How couldourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.
$endgroup$
– 200_success
1 hour ago
1
1
$begingroup$
This code makes no sense. How could
ourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.$endgroup$
– 200_success
1 hour ago
$begingroup$
This code makes no sense. How could
ourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.$endgroup$
– 200_success
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
I think of OOP as being a method to promote reuse by decomposing large data sets into types which tell how to handle their own data, and which can inherit or be inherited to make more complex types without having to duplicate or rewrite the more basic methods of handling the smaller data structures.
That said, you don't really declare any classes or other structures in here, so there isn't a way to make this more "Object Oriented".
You can make it a bit more pythonic by following through on your impulse to have a main function:
import os
import subprocess
def main():
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
if__name__== "__main__":
main()
$endgroup$
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
randal is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212431%2fwhats-a-more-object-oriented-way-to-execute-a-python-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I think of OOP as being a method to promote reuse by decomposing large data sets into types which tell how to handle their own data, and which can inherit or be inherited to make more complex types without having to duplicate or rewrite the more basic methods of handling the smaller data structures.
That said, you don't really declare any classes or other structures in here, so there isn't a way to make this more "Object Oriented".
You can make it a bit more pythonic by following through on your impulse to have a main function:
import os
import subprocess
def main():
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
if__name__== "__main__":
main()
$endgroup$
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
add a comment |
$begingroup$
I think of OOP as being a method to promote reuse by decomposing large data sets into types which tell how to handle their own data, and which can inherit or be inherited to make more complex types without having to duplicate or rewrite the more basic methods of handling the smaller data structures.
That said, you don't really declare any classes or other structures in here, so there isn't a way to make this more "Object Oriented".
You can make it a bit more pythonic by following through on your impulse to have a main function:
import os
import subprocess
def main():
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
if__name__== "__main__":
main()
$endgroup$
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
add a comment |
$begingroup$
I think of OOP as being a method to promote reuse by decomposing large data sets into types which tell how to handle their own data, and which can inherit or be inherited to make more complex types without having to duplicate or rewrite the more basic methods of handling the smaller data structures.
That said, you don't really declare any classes or other structures in here, so there isn't a way to make this more "Object Oriented".
You can make it a bit more pythonic by following through on your impulse to have a main function:
import os
import subprocess
def main():
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
if__name__== "__main__":
main()
$endgroup$
I think of OOP as being a method to promote reuse by decomposing large data sets into types which tell how to handle their own data, and which can inherit or be inherited to make more complex types without having to duplicate or rewrite the more basic methods of handling the smaller data structures.
That said, you don't really declare any classes or other structures in here, so there isn't a way to make this more "Object Oriented".
You can make it a bit more pythonic by following through on your impulse to have a main function:
import os
import subprocess
def main():
cw = os.getcwd()
path = '/scrape'
ourPath = cw + os.path.join(path)
if(ourPath):
os.chdir(ourPath)
os.system('scrapy crawl yellow')
if__name__== "__main__":
main()
answered 3 hours ago
Hack SawHack Saw
27515
27515
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
add a comment |
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
$begingroup$
thank you so much, this is exactly what i was looking for.
$endgroup$
– randal
3 hours ago
add a comment |
randal is a new contributor. Be nice, and check out our Code of Conduct.
randal is a new contributor. Be nice, and check out our Code of Conduct.
randal is a new contributor. Be nice, and check out our Code of Conduct.
randal is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212431%2fwhats-a-more-object-oriented-way-to-execute-a-python-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
This code makes no sense. How could
ourPath
ever be false? What are you really trying to achieve with this code, and why? Please explain, and also retitle the question to state the task accomplished by the code, as per the How to Ask guidelines.$endgroup$
– 200_success
1 hour ago