|
tef posted:
Fixed. You can't use shell=True if you're passing a list of parameters, and if 'plink' is on your %PATH%, it'll be able to find it. Otherwise, you'll have to pass the full path.
|
# ? Nov 6, 2008 05:07 |
|
|
# ? May 12, 2024 02:46 |
|
Habnabit posted:You can't use shell=True if you're passing a list of parameters Didn't realise that, ta.
|
# ? Nov 6, 2008 10:31 |
|
Habnabit posted:You can't use shell=True if you're passing a list of parameters It was working for me.
|
# ? Nov 6, 2008 16:59 |
|
Plink would get hung up. I'm ending up writing an AutoIt script that python will call at the end. I managed to get past the menu with it, so it should work fine.
|
# ? Nov 6, 2008 19:36 |
|
chemosh6969 posted:It was working for me. It might behave differently on Windows because subprocess uses a different API on Windows. On POSIX systems, shell=True with an argument list will cause problems.
|
# ? Nov 6, 2008 23:19 |
|
Habnabit posted:It might behave differently on Windows because subprocess uses a different API on Windows. On POSIX systems, shell=True with an argument list will cause problems. FYI: It works on linux also. Thanks for the help from everyone.
|
# ? Nov 7, 2008 00:02 |
|
chemosh6969 posted:FYI: It works on linux also. It doesn't work on Linux at least. A test directory: code:
code:
code:
|
# ? Nov 7, 2008 01:56 |
|
Try it without brackets: p = subprocess.Popen('ls -l', shell=True) or subprocess.call('ls -l $HOME', shell=True) That's how the examples I found worked. http://blog.doughellmann.com/2007/07/pymotw-subprocess.html chemosh6969 fucked around with this message at 02:28 on Nov 7, 2008 |
# ? Nov 7, 2008 02:25 |
|
chemosh6969 posted:Try it without brackets: Yes, there are two styles for passing parameters: p = subprocess.Popen(['ls', '-l']) p = subprocess.Popen('ls -l', shell=True) The first is more secure, because there's no worries about the parameters being interpreted to contain shell metacharacters.
|
# ? Nov 7, 2008 02:49 |
|
chemosh6969 posted:Try it without brackets: You mean try it as a string rather than a list? That would be equivalent to: code:
tbradshaw fucked around with this message at 03:00 on Nov 7, 2008 |
# ? Nov 7, 2008 02:58 |
|
Need some help: I want to pick out a few "easy to grok" app examples to implement with single-threads, multi threads and then multiprocessing. I want the examples to be as approachable as possible. Ergo, no map-reduces or hadooping
|
# ? Nov 7, 2008 17:13 |
|
Try writing some image filters. Seems like a really easy thing to split up and a lot of the algorithms are well known. Try writing a little physics simulation maybe a few particles in one thread, then split the gfx and physics up.
|
# ? Nov 7, 2008 17:17 |
|
Pivo posted:Try writing a little physics simulation maybe a few particles in one thread, then split the gfx and physics up.
|
# ? Nov 7, 2008 19:51 |
|
Bouquet posted:I have been working on a program that does almost exactly this as part of learning python and 3D graphics stuff. I'm using pyglet, which might be a dependency m0nk3yz would rather avoid for his examples, but I'd be happy to share if you'd like. All in all I was thinking common tools/toys people work with - I want to showcase the simple case
|
# ? Nov 7, 2008 21:49 |
|
m0nk3yz posted:All in all I was thinking common tools/toys people work with - I want to showcase the simple case Recursive processing of an XML tree is pretty common and easy to parallelize.
|
# ? Nov 7, 2008 22:16 |
|
m0nk3yz posted:Need some help: I want to pick out a few "easy to grok" app examples to implement with single-threads, multi threads and then multiprocessing. I want the examples to be as approachable as possible. Ergo, no map-reduces or hadooping The app I just did uses one process for the GUI stuff, and a second for the heavy processing, something like that's a pretty good example IMO.
|
# ? Nov 7, 2008 23:10 |
|
Which of the following is the most pythonic way of checking that an object isn't None: a) if x: b) if not x is None: c) if x is not None: I think I've seen all of these in the wild. I prefer the first one, but when I see pros like Mark Summerfield use c) I wonder if there's a good reason to avoid a).
|
# ? Nov 7, 2008 23:51 |
|
Id4ever posted:Which of the following is the most pythonic way of checking that an object isn't None: First off, anyone using b) is silly since c) says the same thing but is more readable IMHO. Secondly, a) is perfectly acceptable in most cases, but is simply less explicit / accurate than c). It's the same reason that databases have NULL as well as boolean False: sometimes False is an acceptable "good" value, whereas in the same scenario the "empty value" -- None -- would be "bad".
|
# ? Nov 8, 2008 00:18 |
|
Id4ever posted:I think I've seen all of these in the wild. I prefer the first one, but when I see pros like Mark Summerfield use c) I wonder if there's a good reason to avoid a). For example, using a) you would skip that branch for when x was "", [], or 0.
|
# ? Nov 8, 2008 01:05 |
|
No Safe Word posted:The good reason is they do different things. And you really need to be conscious of this. I've written code that did 'if x:' instead of 'if x is not None:' and it took me a while to figure out why I was getting these weird bugs when x, which was a dictionary, was empty.
|
# ? Nov 8, 2008 04:27 |
|
m0nk3yz posted:Need some help: I want to pick out a few "easy to grok" app examples to implement with single-threads, multi threads and then multiprocessing. I want the examples to be as approachable as possible. Ergo, no map-reduces or hadooping Matrix multiplication?
|
# ? Nov 8, 2008 08:49 |
|
I've been having a bit of a Python vs everything else debate with a CS prof at my school. He brought up an example that totally kills Python performance:quote:C code for computing all perfect numbers up to 10000: I did it myself and yeah, I get 0.2 secs for the C code and 12.3 seconds for the Python list comprehension. Expanding out the Python example to be more or less a translation of the C code actually runs a bit slower, 12.7 seconds or so. How can this be?
|
# ? Nov 8, 2008 16:07 |
|
The Python example your CS prof provided runs in 10.6 seconds on my machine because it creates a lot of intermediate lists in memory only for the purpose of iterating over them. The example is hardly equivalent to the examples in other languages. You can get a nice speed up if you use this code:code:
Anyway, C and Haskell are compiled, while Python is interpreted. You should ask your CS prof what his point is. If his point is that Python is slow or something, that's a pretty weaksauce claim because speed is just one out of many requirements and it has never been a measure of how good a language is on its own. And besides, I'm sure you could make this run quicker if you used Psyco.
|
# ? Nov 8, 2008 17:01 |
|
I told him I'd like for it to be an option to do assignments in Python, and he said it's already an option to do them in Scheme, and why wouldn't you use Scheme? He's a bit of a Scheme fanatic. We have two CS 'streams': one starts out in Java, then later introduces you to C. The other starts out in Scheme, and later introduces you to C. Both of them end up in the same 2nd year course about formal language parsing, with the end goal of writing a compiler for a toy language. The options are to use Scheme, Java, and C. A discussion on the newsgroups about how Java doesn't have a built-in notion of tuples used as hash keys, and if you want that behaviour, you have to either write a class with a hashCode and equals function, or use a hashtable of hashtables. The Scheme prof in question replied that you could just use Scheme, which understands how to hash pairs and how to compare them, and furthermore you can have completely heterogeneous mappings. I emailed him that Python can do exactly the same, but is a lot more approachable to people without the functional background. And he's showing me that functional style in Python is half-hearted and slow. Although in this case, the iterative example (directly translated from the C code) is slow too: code:
Oh and I tried Psyco, has no effect on this example.
|
# ? Nov 8, 2008 17:48 |
|
Bonus posted:So almost a double improvement by using generators. Now with less lambda: code:
|
# ? Nov 8, 2008 18:13 |
|
I'll buy a custom title for anyone (edit: the first person I mean) who can solve this in Python and beat or at least match Scheme. I mean, I don't know how to do it. I'm thinking about learning Haskell heh.
Pivo fucked around with this message at 22:04 on Nov 8, 2008 |
# ? Nov 8, 2008 22:02 |
|
Pivo posted:I'll buy a custom title for anyone (edit: the first person I mean) who can solve this in Python and beat or at least match Scheme. I mean, I don't know how to do it. I'm thinking about learning Haskell heh. Likely not possible, without dramatically changing the algorithm or using an experimental Python implementation. The same dearth of features that makes Scheme unsuitable for real projects also allows it to execute very quickly. Also, if tef's solution is moved into a function it's about 2.5 seconds faster (7.6 vs 9.1 on my computer) because the variables will be optimized into registers. Type boxing still limits performance, though.
|
# ? Nov 8, 2008 22:30 |
|
Janin posted:Likely not possible, without dramatically changing the algorithm or using an experimental Python implementation. I figured this would be the case but you never know.
|
# ? Nov 8, 2008 22:47 |
|
Janin posted:Also, if tef's solution is moved into a function it's about 2.5 seconds faster (7.6 vs 9.1 on my computer) because the variables will be optimized into registers. Type boxing still limits performance, though. Shouldn't psyco be taking care of type boxing? Why doesn't psyco provide more benefit with this code?
|
# ? Nov 9, 2008 00:22 |
|
Pivo posted:I figured this would be the case but you never know. Pyrex got me under half a second.
|
# ? Nov 9, 2008 01:09 |
|
deimos posted:Pyrex got me under half a second. Right but Pyrex is generating and compiling an extension to solve the problem in C, and then merely calling it from python. Which is great, but I don't think I'd consider it interesting from the point of "how fast can python do this". You might say that numpy is now an integral enough part of python to make using it a more acceptable comparison, but unfortunately I don't think the nature of the problem lends itself to being helped by numpy. BigRedDot fucked around with this message at 01:17 on Nov 9, 2008 |
# ? Nov 9, 2008 01:12 |
|
BigRedDot posted:Right but Pyrex is generating and compiling an extension to solve the problem in C, and then merely calling it from python. Which is great, but I don't think I'd consider it interesting from the point of "how fast can python do this". The general point is that it's not python the language's fault but CPython's fault. In the same way Haskell is fast Python can be made fast. The overall slowness in the python code is the generator calls inside the sum calls. tef posted:Edit: We could always try running it in iron python. I suspected as much, but it runs slower because it's such a small amount of iterations, there's no chance of JIT optimizing. It ran slightly slower on my machine (Q6600 running Windows Server 2008 x64). deimos fucked around with this message at 02:22 on Nov 9, 2008 |
# ? Nov 9, 2008 02:05 |
|
Greetings... Would it be alright if my n00b-rear end chimed in with a couple questions from 'How To Think Like a Computer Scientist'? I've made it relatively smoothly to Chapter 7 about Strings. I've made it through most of the exercises, but I'm finding that I am super-stuck. Any input here would be appreciated. Exercise: Add body to the following function: code:
code:
code:
-loop traversing the string -string.find returning the location of the input value as it traverses the string -counter is counting the iterations of the loop and returning its final count Things it is not doing properly, that I cannot seem figure out (I realize these elements are not present; I have tried many things): -string.find should update 'start' with the found position, and begin its next search at new 'start' -loop should stop once string.find returns -1 -counter should only count twice, the two times it finds "an" in "banana", and not each iteration of the loop. Can anyone throw me a bone?
|
# ? Nov 9, 2008 03:31 |
|
You can make things way easier:code:
|
# ? Nov 9, 2008 03:41 |
|
Bunson_Honeydew posted:Things it is not doing properly, that I cannot seem figure out (I realize these elements are not present; I have tried many things): You should really try to do the exercise without using string.find, it's kind of cheating. That being said: 1. You're looping twice through the word, which is not what you want, get rid of the for and just use the while. This is why stuff is getting counted twice. 2. If you want start to have the value that string.find returns, you're gonna have to assign it to start not just add 1 to it! Hate to fix your assignment for you instead giving you more hints, but it's not that easy to explain: code:
sw-itch posted:You can make things way easier: That's not very useful if he's trying to learn to code. (albeit my code is un-pythonic, but I think it's illustrating what Bunson is trying to learn. deimos fucked around with this message at 03:54 on Nov 9, 2008 |
# ? Nov 9, 2008 03:48 |
|
Pivo posted:I'll buy a custom title for anyone (edit: the first person I mean) who can solve this in Python and beat or at least match Scheme. I mean, I don't know how to do it. I'm thinking about learning Haskell heh. code:
|
# ? Nov 9, 2008 08:00 |
|
Here's an implementation that uses some recursion and a list comprehension. tails('hey'), for example, produces ['hey','ey','y','']. So it does that and then checks how many elements in that list start with the needle.code:
code:
code:
hey mom its 420 fucked around with this message at 15:22 on Nov 9, 2008 |
# ? Nov 9, 2008 15:15 |
|
Why do you insist on writing Python like you're writing Haskell Bonus posted:or if you're feeling like a code golfer you can write this out in one line:: code:
|
# ? Nov 9, 2008 20:53 |
|
Because God wants me to. Haha, but still, I don't like using the tricks with and, although I admit, doing s.startswith(sub) + count(sub, s[1:]) is nice, I've been doing Haskell so much that I totally forgot that you can add together booleans and numbers.
|
# ? Nov 9, 2008 22:51 |
|
|
# ? May 12, 2024 02:46 |
|
After spending the past two weeks attempting to learn python which is supposedly the most newbie friendly language out there, my mind is blown by how people manage to program computer games and rocket ships with this.
|
# ? Nov 10, 2008 06:03 |