Whats a more object oriented way to execute a python script












-1












$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')









share|improve this question







New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 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
















-1












$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')









share|improve this question







New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 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














-1












-1








-1





$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')









share|improve this question







New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$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






share|improve this question







New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









randalrandal

11




11




New contributor




randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






randal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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














  • 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








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










1 Answer
1






active

oldest

votes


















0












$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()





share|improve this answer









$endgroup$













  • $begingroup$
    thank you so much, this is exactly what i was looking for.
    $endgroup$
    – randal
    3 hours ago











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.










draft saved

draft discarded


















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









0












$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()





share|improve this answer









$endgroup$













  • $begingroup$
    thank you so much, this is exactly what i was looking for.
    $endgroup$
    – randal
    3 hours ago
















0












$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()





share|improve this answer









$endgroup$













  • $begingroup$
    thank you so much, this is exactly what i was looking for.
    $endgroup$
    – randal
    3 hours ago














0












0








0





$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()





share|improve this answer









$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()






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • $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










randal is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?