|
Cicero posted:I'm using the subprocess module to execute shell commands inside a python script. I want the stdout from these new processes to basically shut up because they're really verbose but the print statements inside my python script to continue working. Right now it seems to be either both or none. I'm working on windows if that matters. Probably best to just redirect stderr and stdout of the command you're running to NUL, like this: code:
|
# ? Aug 6, 2011 00:31 |
|
|
# ? Jun 11, 2024 20:03 |
|
Cicero posted:I'm using the subprocess module to execute shell commands inside a python script. I want the stdout from these new processes to basically shut up because they're really verbose but the print statements inside my python script to continue working. Right now it seems to be either both or none. I'm working on windows if that matters. I had a similar issue with a batch processing routine, and ended up doing this: code:
EDIT: oh damnit, missed that there was a new page. I like my method a litle better, but it depends on how useful the output would be for you.
|
# ? Aug 6, 2011 05:08 |
|
Cicero posted:I'm using the subprocess module to execute shell commands inside a python script. I want the stdout from these new processes to basically shut up because they're really verbose but the print statements inside my python script to continue working. Right now it seems to be either both or none. I'm working on windows if that matters. I've never actually had subprocess commands outputting anything unless I specifically tell it to. Setting the stderr and stdout kwargs to subprocess.PIPE gives you a file-like object that has the output streams with no issues. Here's the PMOTW on subprocess, and it's pretty simple: http://blog.doughellmann.com/2007/07/pymotw-subprocess.html On the other handle if you're just blindly calling subprocess.call everywhere, then yeah you'd get the command output interfering with your print statements
|
# ? Aug 6, 2011 05:16 |
|
In subprocess, the child inherits stdout from the parent by default. Try passing stdout=subprocess.PIPE into the subprocess command http://docs.python.org/library/subprocess.html When you do this, the popen object returned will have a stdout attribute you can read from and close, like a file handle.
|
# ? Aug 6, 2011 12:01 |
|
tef posted:By the way, it is a bag of functions and variables as implemented within python. Python is not message style OO like Smalltalk, Obj-C or Ruby, it is closer to Simula style OO. It doesn't matter. I'm talking about how to think in OO, and modelling the problem is pretty much your canonical approach.
|
# ? Aug 7, 2011 07:42 |
|
As the OP hasn't been updated in nearly a year and a half, what is the best online resource for learning Python? I know HTML, CSS, PHP, Visual Basic (heh) and C++, I'm looking to learn Python for fun.
|
# ? Aug 7, 2011 16:38 |
|
Doctor Claw posted:As the OP hasn't been updated in nearly a year and a half, what is the best online resource for learning Python? I know HTML, CSS, PHP, Visual Basic (heh) and C++, I'm looking to learn Python for fun. I constantly point folks who have a programming background at the MIT course in the OP. It's very well done and doesn't really go into the tedium of: "This is an if-statement ... This is a for-loop ..." because (I assume) MIT assumes that people know the ultra basics of programming, even in the intro level.
|
# ? Aug 7, 2011 19:04 |
|
spankweasel posted:I constantly point folks who have a programming background at the MIT course in the OP. It's very well done and doesn't really go into the tedium of: "This is an if-statement ... This is a for-loop ..." because (I assume) MIT assumes that people know the ultra basics of programming, even in the intro level. What would be the best guide for people who DID want all that if-statement/for-loop information?
|
# ? Aug 7, 2011 19:07 |
|
Yoshimo posted:What would be the best guide for people who DID want all that if-statement/for-loop information? http://learnpythonthehardway.org/
|
# ? Aug 7, 2011 19:30 |
|
TasteMyHouse posted:http://learnpythonthehardway.org/ this. a thousand times this.
|
# ? Aug 8, 2011 01:11 |
|
TasteMyHouse posted:http://learnpythonthehardway.org/ Seconding this. I didn't learn python this way the first time, but when I went through this, I learned so much more about Python than I ever did by just going seat of the pants of "how the hell do I do this"??
|
# ? Aug 9, 2011 04:44 |
|
I stuck on the last part of a major project for my Python programming class. The program we're writing has to do all of the following things: 1.) Use a card object defined by the teacher to determine the value of a 5 card poker hand containing 5 cards. 2.) Take a numeric (positive integer) input from the user and repeat step 1 as many times. Record all of the hands to a text file 3.) Perform a simple statistical analysis of all of the hands collected from steps 1 and 2, and record this to a text file as well. 4.) If the user enters an input on step 2 that's not a positive integer, prompt the user to re-enter the input. I can't for the life of me figure out part 4. Right now, the first part of my code looks like this: code:
Note: this is just the first couple lines of code, I don't see the need to post the entire thing.
|
# ? Aug 9, 2011 05:17 |
|
Harold Ramis Drugs posted:Is there a way I could put an 'if' or a 'while' statement on the first couple lines of code that will recursively restart the main function if the first input is not a positive integer? (before you ask "how?", you do it just like you said to do it) You could also put the input into its own procedure, which returns when the user has entered a positive integer.
|
# ? Aug 9, 2011 05:20 |
|
What are peoples recomendations on editors. I cant keep pycharm stable on Lion anymore with its constant lockups, and for the loving life of me I cant get eclipse to recognise its python path source directories for django. I'm losing days of work to this poo poo and its driving me loving insane. e: Oh great aptana is just an eclipse rebrand with that crazy retarded virtual file-structure poo poo. Just give me a directory listing you over-engineering java wingnuts grrrrrrrrr e2: Ok, 15 minutes of "rebuilding workspace" later, I think Aptana just failed the audition. :/ Any other recomendations for a non eclipse or IDEA based python editor that "gets" django? e3: BBedit cant have different docs in a split window. Delete. What else is there? e4: Oh hey jEdit is ugly as gently caress, but is stable , highlights python and html/js properly, has a multi-doc split windows and appears to just work. You'll do , you ugly little text editor! Shame about the eye-searing font though :/ e5: Oh hey sublime-text is pretty drat sweet! duck monster fucked around with this message at 08:27 on Aug 9, 2011 |
# ? Aug 9, 2011 05:26 |
|
Janin posted:Yep! I'm feeling pretty retarded now, and I've been trying different types of 'while' and 'if' loops to get this working. Could you please show me how to make an input statement that will recursively restart the main function if any non-integer or integer < 1 is entered? I'm kicking myself in the head right now. VVVVV Thanks VVVVVV Harold Ramis Drugs fucked around with this message at 06:53 on Aug 9, 2011 |
# ? Aug 9, 2011 06:30 |
|
Harold Ramis Drugs posted:I'm feeling pretty retarded now, and I've been trying different types of 'while' and 'if' loops to get this working. Could you please show me how to make an input statement that will recursively restart the main function if any non-integer or integer < 1 is entered? I'm kicking myself in the head right now. Recursive main, checking for negative integers: code:
code:
code:
|
# ? Aug 9, 2011 06:46 |
|
duck monster posted:What are peoples recomendations on editors. I cant keep pycharm stable on Lion anymore with its constant lockups, and for the loving life of me I cant get eclipse to recognise its python path source directories for django. I'm losing days of work to this poo poo and its driving me loving insane. It's pretty barebones, but I like TextWrangler when doing one-off scripting. I run PyCharm 1.5.3 on Lion (new mac mini) with no issues at all so I'm confused what's happening to you. VVV PyScripter is alright in general, and since duck monster is on Mac, I'll mention that I was able to get it *working* with Wine on mac Lurchington fucked around with this message at 21:11 on Aug 9, 2011 |
# ? Aug 9, 2011 14:23 |
|
duck monster posted:What are peoples recomendations on editors. edit: ^^ Totally missed that he wanted something Mac-specific. Oh well; I'll leave it here for others who want a nice, free, Windows-only (or Wine, apparently) editor. _aaron fucked around with this message at 01:11 on Aug 10, 2011 |
# ? Aug 9, 2011 17:05 |
|
MacVim
|
# ? Aug 9, 2011 17:11 |
|
People all over the internet recommend Dive into Python, but it's not popular around here, right?
|
# ? Aug 9, 2011 18:01 |
|
Grabulon posted:People all over the internet recommend Dive into Python, but it's not popular around here, right? It's terrible.
|
# ? Aug 9, 2011 18:25 |
|
Hi guys I am very new to python and I am trying to write a script that pulls the newest file (this server gets a data dump every hour) from a sftp sever. I played around with the paramiko module and was able to write a script to pull a file of a certain name but I am completely lost when it comes to determining the newest file. Im not sure where to start, and I supposed to interpret os.stat? The files do have naming scheme which incorporates time/date etc etc. Any tutorials out there? Thanks
|
# ? Aug 9, 2011 19:00 |
|
I recommend you use Fabric instead of paramiko, it has a nicer API built on top of paramiko. I've been using it to remote deploy our server stuff and it's really nice.
|
# ? Aug 9, 2011 19:10 |
|
I'd recommend paramiko when all you need is to log in and execute a remote script and maybe get the output. Otherwise I agree that Fabric is better for the heavier stuff. For what it's worth, it sounds like rsync with ssh keys is basically what you want?
|
# ? Aug 9, 2011 21:12 |
|
duck monster posted:What are peoples recomendations on editors. I cant keep pycharm stable on Lion anymore with its constant lockups, and for the loving life of me I cant get eclipse to recognise its python path source directories for django. I'm losing days of work to this poo poo and its driving me loving insane. They're both worth the price. TextMate is more flexible plugin-wise but Coda's integrated SFTP is way better than the available TextMate plugins.
|
# ? Aug 9, 2011 22:14 |
|
I'm pretty happy with Sublime text 2 at the moment. It seems to hit my feature list loving nicely and it appears to "get" django pretty well.
|
# ? Aug 10, 2011 06:38 |
|
I just started my first project of decent scale in Python. This, of course, means testing. Except that I really didn't like the look of unittest, and nose, and py.test (AKA JUnit). So I ported a teensy testing lib that I wrote for Javascript, and added a runner/harness script. If you're familiar with Perl's Test::More, it'll look familiar. https://github.com/firepear/nanotest-py/ Let me know if it's of use to you, and/or if you have concrete requests for improvement.
|
# ? Aug 10, 2011 06:56 |
|
duck monster posted:I'm pretty happy with Sublime text 2 at the moment. It seems to hit my feature list loving nicely and it appears to "get" django pretty well. I'm trying out ST2 also, At the moment I like it over pycharm somewhat, I still have some problems with it over pycharm, like it's horrible spell checker, the fact that it doesn't seem to be able to handle virtualenvs/tab completion (least I havn't found out how yet), not saving your open files when switching projects, and no tab complete inside of strings for django settings.
|
# ? Aug 10, 2011 09:45 |
|
Thermopyle posted:It's terrible. Really? I just compared it and it is a lot more sensible and readable than Zed Shaw's self congratulatory wank fest.
|
# ? Aug 10, 2011 14:47 |
|
duck monster posted:I'm pretty happy with Sublime text 2 at the moment. It seems to hit my feature list loving nicely and it appears to "get" django pretty well. It's also written in python, if you want to extend it. The API is pretty nice too. If I used a GUI, it'd be Sublime 2!
|
# ? Aug 10, 2011 18:41 |
|
I've used IDLE and had no real issues with it. I know it's not liked very much in Python editor circles though. Aquamacs might be a good alternative, and really Aquamacs is awesome as it is.
|
# ? Aug 11, 2011 05:15 |
|
Hello everyone, quite new to Python/programming in general and I'm trying to remove certain characters from a string.code:
Using Python 3.2 in case that matters.
|
# ? Aug 11, 2011 10:30 |
|
code:
|
# ? Aug 11, 2011 10:54 |
|
Angryhead posted:Hello everyone, quite new to Python/programming in general and I'm trying to remove certain characters from a string. Regex (aka regular expressions) are a powerful way to process text. http://docs.python.org/py3k/library/re.html#re.sub
|
# ? Aug 11, 2011 12:10 |
|
I resisted learning regexes (regeces?) for a long time (I'm a total hobbyist) until I did some screen scraping and really needed them. I like Red Mike's solution to this problem (and it's probably a handy reminder that you can iterate through strings so easily) but don't wait as long as I did to dive into regex!
|
# ? Aug 11, 2011 20:24 |
|
3rd'd, the syntax is a bit rough (english slang meaning difficult) but skys the limit once you get over that hump.
|
# ? Aug 11, 2011 20:33 |
|
tripwire posted:Really? I just compared it and it is a lot more sensible and readable than Zed Shaw's self congratulatory wank fest. Not that I keep up with beginner python books (for example, I don't know who the hell Zed Shaw is or what book you're talking about), but when I was first learning python and programming (neglecting the fact that I learned QBasic 20 years ago) a couple years ago, Dive into Python was very irritating. I'm not alone in my feeling that it's not very good: quote:Dive Into Python isn't just bad because of the use of ODBC, it's also just full of bad initial examples. Take a look at your first Python program and boggle at all the bizarre stuff a beginner has to suddenly comprehend: I get that everyone learns in different ways, but it certainly seems to me that most people won't find Dive into Python a very good beginners book. FWIW, I struggled with Dive Into Python for awhile before switching to Python for Software Design - How to Think Like a Computer Scientist and breezing through it and learning a ton.
|
# ? Aug 11, 2011 21:35 |
|
I found the offical documentation a bit poo poo to be honest. Got lots more out of the community in general. Go fire up that browser!
|
# ? Aug 11, 2011 21:42 |
|
Thermopyle posted:I'm not alone in my feeling that it's not very good I too, think the actual python docs are pretty dreadful. At least they've improved; <=2.5 docs were a nightmare both to navigate and read - the new sphinx docs are a godsend, in that respect.
|
# ? Aug 11, 2011 22:10 |
|
|
# ? Jun 11, 2024 20:03 |
|
Since we're talking about LPTHW, I started reading just for fun. I've been doing the "extra credit", but I am stuck on Example 17:code:
code:
|
# ? Aug 11, 2011 22:21 |