Need help improving number guessing game

2008-12-13 Thread feba
#!/usr/bin/python/ #Py3k, UTF-8 import random print(" --- WELCOME TO THE SUPER NUMBER GUESSING GAME --- " + ("\n" * 5)) pnum = int(input("1 OR 2 PLAYER?\nP#: ")) target = random.randint(1, 99) #Pick a random number under two digits guess1 = 0 #Zero will never be picked as target... guess2 = 0 #

Re: Umlauts in idle

2008-12-13 Thread Martin v. Löwis
> When I try to use umlauts in idle it will only print out as Unicode > escape characters. Is it possible to configure idle to print them as > ordinary characters? Did you really use the print statement? They print out fine for me. Regards, Martin -- http://mail.python.org/mailman/listinfo/python

setup.py installs modules to a wrong place

2008-12-13 Thread Michal Ludvig
Hi, I have recently seen some reports from users of my s3cmd script [1] who installed the package using the provided distutils-based setup.py and immediately after installation the script failed to run because it couldn't find its modules. Here's an example session from Mac OS X, but similar beha

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
feba wrote: #!/usr/bin/python/ #Py3k, UTF-8 import random print(" --- WELCOME TO THE SUPER NUMBER GUESSING GAME --- " + ("\n" * 5)) pnum = int(input("1 OR 2 PLAYER?\nP#: ")) target = random.randint(1, 99) #Pick a random number under two digits guess1 = 0 #Zero will never be picked as target..

Re: Need help improving number guessing game

2008-12-13 Thread Steven D'Aprano
On Sat, 13 Dec 2008 00:57:12 -0800, feba wrote: > I have one major problem with this; the 'replay' selection. It quits if > you put in 0, as it should, and continues if you put in any other > number. However, if you just press enter, it exits with an error. it > also looks really ugly, and I'm sur

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: 1. Refactor. You should look at your code and see where you repeat the same or similar patterns, see where they differ, make functions, and make the differences parameters to the function call: def guess(player, p1score, p2score): guess1 = int(input("\n>> ")) if guess1

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
I forgot to return target: def guess(player, p1score, p2score): target = None guess1 = int(input("\n>> ")) if guess1 > 100: print("ONLY NUMBERS FROM 1 TO 99") elif guess1 > target: print("TOO HIGH") elif guess1 == target: print("GOOD JOB, PLAYER %s! THE SCORE IS:" % player)

Re: Umlauts in idle

2008-12-13 Thread a_olme
On 13 Dec, 10:38, "Martin v. Löwis" wrote: > > When I try to use umlauts in idle it will only print out as Unicode > > escape characters. Is it possible to configure idle to print them as > > ordinary characters? > > Did you really use the print statement? They print out fine for me. > > Regards,

Re: Removing None objects from a sequence

2008-12-13 Thread Steven D'Aprano
On Fri, 12 Dec 2008 19:02:24 -0500, Terry Reedy wrote: > Tim Chase wrote: >>> If you want to literally remove None objects from a list(or >>> mutable sequence) >>> >>> def deNone(alist): >>>n=len(alist) >>>i=j=0 >>>while i < n: >>> if alist[i] is not None: >>>alist[j]

Re: var or inout parm?

2008-12-13 Thread Marc 'BlackJack' Rintsch
On Sat, 13 Dec 2008 02:20:59 +0100, Hrvoje Niksic wrote: > Saner (in this respect) behavior in the tuple example would require a > different protocol. I don't understand why Python doesn't just call > __iadd__ for side effect if it exists. The decision to also rebind the > result of __i*__ metho

__future__ and compile: unrecognised flags

2008-12-13 Thread Poor Yorick
I have a future statement in a script which is intended to work in 2.6 and 3. Shouldn't compile flags in __future__ objects essentially be noops for versions that already support the feature? doctest is complaining about unrecognised flags. This illustrates the problem: Python 3.0 (r30:67507,

Re: Umlauts in idle

2008-12-13 Thread Marc 'BlackJack' Rintsch
On Sat, 13 Dec 2008 02:58:48 -0800, a_olme wrote: > On 13 Dec, 10:38, "Martin v. Löwis" wrote: >> > When I try to use umlauts in idle it will only print out as Unicode >> > escape characters. Is it possible to configure idle to print them as >> > ordinary characters? >> >> Did you really use the

Re: Removing None objects from a sequence

2008-12-13 Thread Filip Gruszczyński
Just to be clear, I decided to use generator by alex23, as it seems simple, short and understandable. Still reading this thread was quite interesting, thanks :-) -- Filip Gruszczyński -- http://mail.python.org/mailman/listinfo/python-list

Parallelizing python code - design/implementation questions

2008-12-13 Thread stdazi
Hello! I'm about to parallelize some algorithm that turned out to be too slow. Before I start doing it, I'd like to hear some suggestions/hints from you. The algorithm essentially works like this: There is a iterator function "foo" yielding a special kind permutation of [1,n]. The main progr

Re: __future__ and compile: unrecognised flags

2008-12-13 Thread Steve Holden
Poor Yorick wrote: > I have a future statement in a script which is intended to work in 2.6 and 3. > Shouldn't compile flags in __future__ objects essentially be noops for > versions > that already support the feature? doctest is complaining about unrecognised > flags. This illustrates the proble

Re: Removing None objects from a sequence

2008-12-13 Thread bearophileHUGS
Steven D'Aprano: > The algorithm is unclear: try explaining > what you are doing in English, and see how difficult it is. That algorithm is a standard one, and quite clear. Any programmer worth his/her/hir salt has to be able to understand that. I agree that the idiom with the list comp (algorith

Shorter tracebacks

2008-12-13 Thread bearophileHUGS
When I write recursive code in Python I sometimes go past the maximum allowed stack depth, so I receive a really long traceback. The show of such traceback on my screen is very slow (despite a CPU able to perform billions of operations each second). So I think I'd like something to shorten them. I

Re: Shorter tracebacks

2008-12-13 Thread rdmurray
On Sat, 13 Dec 2008 at 06:13, bearophileh...@lycos.com wrote: When I write recursive code in Python I sometimes go past the maximum allowed stack depth, so I receive a really long traceback. The show of such traceback on my screen is very slow (despite a CPU able to perform billions of operations

Re: var or inout parm?

2008-12-13 Thread Hrvoje Niksic
Marc 'BlackJack' Rintsch writes: > On Sat, 13 Dec 2008 02:20:59 +0100, Hrvoje Niksic wrote: > >> Saner (in this respect) behavior in the tuple example would require >> a different protocol. I don't understand why Python doesn't just >> call __iadd__ for side effect if it exists. The decision to

Re: Shorter tracebacks

2008-12-13 Thread Peter Otten
bearophileh...@lycos.com wrote: > When I write recursive code in Python I sometimes go past the maximum > allowed stack depth, so I receive a really long traceback. The show of > such traceback on my screen is very slow (despite a CPU able to > perform billions of operations each second). So I thi

Re: Bidirectional Networking

2008-12-13 Thread Emanuele D'Arrigo
On Dec 12, 9:04 pm, "Gabriel Genellina" wrote: > If you're using 2.5 or older, override serve_forever: > > def serve_forever(self): > while not getattr(self, 'quit', False): > self.handle_request() > > and set the server 'quit' attribute to True in response to some comma

Re: Bidirectional Networking

2008-12-13 Thread Emanuele D'Arrigo
On Dec 13, 12:08 am, "James Mills" wrote: > Just as a matter of completeness for my own suggestion, here > is my implementation of your code (using circuits): It's longer! But I bet is a little bit more resilient against all sorts of problems that arise while using network connections. Well, tha

zip a created file

2008-12-13 Thread frendy zhang
if form.accepts(request.vars,session): for table in db.tables: rows=db(db[table].id).select() print rows open(str(os.sep).join([os.getcwd(), 'applications', request.application, 'databases', table+'.csv']),'w').write(s

encrypt and descrypt a created file

2008-12-13 Thread frendy zhang
if form.accepts(request.vars,session): for table in db.tables: rows=db(db[table].id).select() print rows open(str(os.sep).join([os.getcwd(), 'applications', request.application, 'databases', table+'.csv']),'w').write(s

Re: Python is slow

2008-12-13 Thread Isaac Gouy
On Dec 12, 6:58 am, bearophileh...@lycos.com wrote: > sturlamolden: > > > On a recent benchmark Java 6 -server beats C compiled by GCC 4.2.3 And > > most of that magic comes from an implementation of a dynamically typed > > language (Smalltalk). [...] > >http://shootout.alioth.debian.org/u32q/bench

Re: Python is slow

2008-12-13 Thread Isaac Gouy
On Dec 12, 11:41 am, Bruno Desthuilliers wrote: > sturlamolden a écrit : > (snip) > > > Creating a fast implementation of a dynamic language is almost rocket > > science. But it has been done. There is Stronghold, the fastest > > version of Smalltalk known to man, on which the Sun Java VM is based

Re: Bidirectional Networking

2008-12-13 Thread Emanuele D'Arrigo
Hey Bryan, thank you for your reply! On Dec 13, 3:51 am, Bryan Olson wrote: > > Is it possible then to establish both a server and a client in the > > same application? > > Possible, and not all that hard to program, but there's a gotcha. > Firewalls, including home routers and software firewalls

Re: Need help improving number guessing game

2008-12-13 Thread feba
#!/usr/bin/python #Py3k, UTF-8 import random def startup(): print("WELCOME TO THE SUPER NUMBER GUESSING GAME!") global pnum, play, player, p1sc, p2sc pnum = int(input("1 OR 2 PLAYERS?\n> ")) play = True player = "P1" #P1 goes first p1sc = 0 #Number of times... p2sc = 0

Why %e not in time.strftime directives?

2008-12-13 Thread Leo jay
Any special reasons? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why %e not in time.strftime directives?

2008-12-13 Thread skip
Leo> Any special reasons? Nobody thought to add it? Got a patch? -- Skip Montanaro - s...@pobox.com - http://smontanaro.dyndns.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Why %e not in time.strftime directives?

2008-12-13 Thread Tim Chase
Any special reasons? Because it is there (at least on my Debian box)? t...@rubbish:~$ python Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) [GCC 4.2.4 (Debian 4.2.4-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.str

Re: Netbeans Early Access and Python3

2008-12-13 Thread vk
Netbeans is a very polished IDE. I just tried the Python EA plugin, however, and it does not have 3.x support as of now. -- http://mail.python.org/mailman/listinfo/python-list

Re: encrypt and descrypt a created file

2008-12-13 Thread Tim Chase
open(str(os.sep).join([ os.getcwd(), 'applications', request.application, 'databases', table+'.csv']),'w').write(str(db(db[table].id).select ())) How can i encrypt and descrypt the created file above?? Well, as I was recently admonished (and have come to love), the firs

Re: Removing None objects from a sequence

2008-12-13 Thread Steven D'Aprano
On Sat, 13 Dec 2008 11:07:53 +, Steven D'Aprano wrote: > Now, sure, most of the work in Tim's version is executed in fast C code > instead of slow Python code. Say what??? I'm sorry, I must have been smoking crack when I wrote that. It does nothing of the sort. Tim's version is pure Python.

Re: Removing None objects from a sequence

2008-12-13 Thread Steven D'Aprano
On Sat, 13 Dec 2008 06:00:09 -0800, bearophileHUGS wrote: > Steven D'Aprano: >> The algorithm is unclear: try explaining what you are doing in English, >> and see how difficult it is. > > That algorithm is a standard one, and quite clear. Any programmer worth > his/her/hir salt has to be able to

Re: Best way of debigging a C extension

2008-12-13 Thread Paul Moore
On 11 Dec, 23:57, Christian Heimes wrote: > Paul Moore schrieb: > > That's what I thought. I was just hoping that using a debug build of > > an extension would be usable with a standard release build of Python, > > as that's what will be easy for most people to set up. > > A debug build changes la

[OT] stable algorithm with complexity O(n)

2008-12-13 Thread David Hláčik
Hi guys, i am really sorry for making offtopic, hope you will not kill me, but this is for me life important problem which needs to be solved within next 12 hours.. I have to create stable algorithm for sorting n numbers from interval [1,n^2] with time complexity O(n) . Can someone please give m

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Diez B. Roggisch
David Hláčik schrieb: Hi guys, i am really sorry for making offtopic, hope you will not kill me, but this is for me life important problem which needs to be solved within next 12 hours.. I have to create stable algorithm for sorting n numbers from interval [1,n^2] with time complexity O(n) . C

Re: zip a created file

2008-12-13 Thread Tino Wildenhain
frendy zhang wrote: > if form.accepts(request.vars,session): > for table in db.tables: > rows=db(db[table].id).select() > print rows > open(str(os.sep).join([os.getcwd(), 'applications', > request.application, 'databases', >

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread David Hláčik
> Unless I grossly miss out on something in computer science 101, the lower > bound for sorting is O(n * log_2 n). Which makes your task impossible, > unless there is something to be assumed about the distribution of numbers in > your sequence. There is n numbers from interval [1 , n^2] I should d

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Dan Upton
On Sat, Dec 13, 2008 at 2:00 PM, David Hláčik wrote: >> Unless I grossly miss out on something in computer science 101, the lower >> bound for sorting is O(n * log_2 n). Which makes your task impossible, >> unless there is something to be assumed about the distribution of numbers in >> your sequen

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Wojciech Muła
"David Hláčik" wrote: > I have to create stable algorithm for sorting n numbers from interval > [1,n^2] with time complexity O(n) . Some kind of radix sort or counting sort. These algo. has O(n) complexity. w. -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Duncan Booth
"Diez B. Roggisch" wrote: > David Hláčik schrieb: >> Hi guys, >> >> i am really sorry for making offtopic, hope you will not kill me, but >> this is for me life important problem which needs to be solved within >> next 12 hours.. >> >> I have to create stable algorithm for sorting n numbers f

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread MRAB
Diez B. Roggisch wrote: David Hláčik schrieb: Hi guys, i am really sorry for making offtopic, hope you will not kill me, but this is for me life important problem which needs to be solved within next 12 hours.. I have to create stable algorithm for sorting n numbers from interval [1,n^2] with

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Diez B. Roggisch
Duncan Booth schrieb: "Diez B. Roggisch" wrote: David Hlá�ik schrieb: Hi guys, i am really sorry for making offtopic, hope you will not kill me, but this is for me life important problem which needs to be solved within next 12 hours.. I have to create stable algorithm for sorting n number

Bidrectional Subprocess Communication

2008-12-13 Thread Emanuele D'Arrigo
Hi everybody, I'm trying to replicate the positive results of the Client/Server scripts from the thread "Bidirectional Networking", but this time using a Process/SubProcess architecture. The SubProcess, acting as a server, is working just fine. But the Process executing the SubProcess, the client

Re: Parallelizing python code - design/implementation questions

2008-12-13 Thread Philip Semanchuk
On Dec 13, 2008, at 7:00 AM, stdazi wrote: Hello! I'm about to parallelize some algorithm that turned out to be too slow. Before I start doing it, I'd like to hear some suggestions/hints from you. Hi stdazi, If you're communicating between multiple processes with Python, you might find my

Re: var or inout parm?

2008-12-13 Thread sturlamolden
On 13 Des, 02:20, Hrvoje Niksic wrote: > > tmp = mytuple.__getitem__(0) > > tmp = tmp.__iadd__(1) > > mytuple.__setitem__(0, tmp) # should this always raise an exception? > > What do you mean by "a sane parser"?  This is exactly what happens in > current Python.   Yes, but Steve Holden was sugge

Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread John Machin
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = u'\u9876' >>> x u'\u9876' # As expected Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win 32 Type "h

Re: Problems running on HP Intel duo core machine

2008-12-13 Thread Aaron Brady
On Dec 11, 3:16 pm, jim-on-linux wrote: > Aaron, > > The TraceBack is : > > TraceBack: > File win32ui.pyc, line 12, in > File win32ui.pyc Line 10, in _load > ImportError: DLL Load Failed: The specified module > could not be found. snip > > Both modules 'win32api.pyd'  and win32ui.pyd are in > >

curses and refreshing problem

2008-12-13 Thread Karlo Lozovina
Hi, I'm trying to implement text output interface, something similar to wget, using curses module. There are just two things I can't find out how to do: prevent curses from clearing the terminal when starting my program, and leaving my output after the program closes. Any way to do this with cu

Re: var or inout parm?

2008-12-13 Thread sturlamolden
On 13 Des, 21:26, sturlamolden wrote: > Python methods always have a return value, even those that seem to do > not - they silently return None. Thus, __iadd__ must return self to > avoid rebinding to None. Except for immutable types, for which __iadd__ must return a new instance. -- http://

Re: var or inout parm?

2008-12-13 Thread Aaron Brady
On Dec 12, 7:31 am, Steve Holden wrote: > sturlamolden wrote: > > On Dec 12, 1:56 pm, sturlamolden wrote: > > >> That is because integers are immutable. When x += 1 is done on an int, > >> there will be a rebinding. But try the same on say, a numpy array, and > >> the result will be different: sn

Re: Python is slow

2008-12-13 Thread sturlamolden
On 10 Des, 19:42, cm_gui wrote: > And it is not just this Python site that is slow. There are many many > Python sites which are very slow. And please don’t say that it could > be the web hosting or the server which is slow — because when so many > Python sites are slower than PHP sites, it could

Re: stable algorithm with complexity O(n)

2008-12-13 Thread Aaron Brady
On Dec 13, 1:17 pm, Duncan Booth wrote: > "Diez B. Roggisch" wrote: > > > > > David Hláčik schrieb: > >> Hi guys, > > >> i am really sorry for making offtopic, hope you will not kill me, but > >> this is for me life important problem which needs to be solved within > >> next 12 hours.. > > >> I h

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Vlastimil Brom
2008/12/13 John Machin : > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. x = u'\u9876' x > u'\u9876' > > # As expected > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MS

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Chris Rebert
On Sat, Dec 13, 2008 at 12:28 PM, John Machin wrote: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. x = u'\u9876' x > u'\u9876' > > # As expected > > Python 3.0 (r30:6750

Re: Python is slow

2008-12-13 Thread Benjamin Kaplan
On Sat, Dec 13, 2008 at 3:35 PM, sturlamolden wrote: > On 10 Des, 19:42, cm_gui wrote: > > > And it is not just this Python site that is slow. There are many many > > Python sites which are very slow. And please don't say that it could > > be the web hosting or the server which is slow — because

Re: ActivePython 2.6.1.1 and 3.0.0.0 released!

2008-12-13 Thread Trent Mick
Kay Schluehr wrote: On 13 Dez., 00:16, Trent Mick wrote: Note that currently PyWin32 is not included in ActivePython 3.0. Is there any activity in this direction? The PyWin32 CVS tree is getting checkins from Mark Hammond and Roger Upole with a py3k tag. I'm not sure how close they are cu

Re: stable algorithm with complexity O(n)

2008-12-13 Thread Benjamin Kaplan
2008/12/13 Aaron Brady > On Dec 13, 1:17 pm, Duncan Booth wrote: > > "Diez B. Roggisch" wrote: > > > > > > > > > David Hláčik schrieb: > > >> Hi guys, > > > > >> i am really sorry for making offtopic, hope you will not kill me, but > > >> this is for me life important problem which needs to be

Re: stable algorithm with complexity O(n)

2008-12-13 Thread Duncan Booth
Aaron Brady wrote: >So, what's the group policy on helping with homework? rhetorical> In my book anyone who is dumb enough to ask for homework help on a newsgroup and doesn't acknowledge that when they hand in their answer deserves whatever they get. Oh, and of course there are 2 deliberate

pypi package dates

2008-12-13 Thread sokol
Am I missing something? There are no release dates for packages in pypi. One cannot have an idea how current the package is... -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread John Machin
On Dec 14, 8:07 am, "Chris Rebert" wrote: > On Sat, Dec 13, 2008 at 12:28 PM, John Machin wrote: > > > Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > x = u'\u9876' > x

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Arnaud Delobelle
"David Hláčik" writes: > Hi guys, > > i am really sorry for making offtopic, hope you will not kill me, but > this is for me life important problem which needs to be solved within > next 12 hours.. > > I have to create stable algorithm for sorting n numbers from interval > [1,n^2] with time compl

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Martin v. Löwis
>> This is intended behavior. > > I see. That means that the behaviour in Python 1.6 to 2.6 (i.e. > encoding the text using the repr() function (as then defined) was not > intended behaviour? Sure. This behavior has not changed. It still uses repr(). Of course, the string type has changed in 3.0

[ANN] Python 2.4.6 and 2.5.3, release candidate 1

2008-12-13 Thread Martin v. Löwis
On behalf of the Python development team and the Python community, I'm happy to announce the release candidates of Python 2.4.6 and 2.5.3. 2.5.3 is the last bug fix release of Python 2.5. Future 2.5.x releases will only include security fixes. According to the release notes, over 100 bugs and patc

1000 Earn Dollars $$$

2008-12-13 Thread yameena...@gmail.com
"How To Make $1,000,000 THIS YEAR With our Online Business" -- http://mail.python.org/mailman/listinfo/python-list

http://1000earndollars.blogspot.com/

2008-12-13 Thread yameena...@gmail.com
"How To Make $1,000,000 THIS YEAR With our Online Business" -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread John Machin
On Dec 14, 9:20 am, "Martin v. Löwis" wrote: > >> This is intended behavior. > > > I see. That means that the behaviour in Python 1.6 to 2.6 (i.e. > > encoding the text using the repr() function (as then defined) was not > > intended behaviour? > > Sure. "Sure" as in "sure, it was not intended be

Re: Bidirectional Networking

2008-12-13 Thread Bryan Olson
Emanuele D'Arrigo wrote: Hey Bryan, thank you for your reply! Bryan Olson wrote: Is it possible then to establish both a server and a client in the same application? Possible, and not all that hard to program, but there's a gotcha. Firewalls, including home routers and software firewalls, typi

Re: Bidirectional Networking

2008-12-13 Thread Emanuele D'Arrigo
On Dec 13, 11:13 pm, Bryan Olson wrote: > Software firewalls will often simply refuse incoming connections. The > basic protection of the garden-variety home router comes from "network > address translation" (NAT), in which case TCP connections initiated from > the inside will generally work, rega

subprocess to C program

2008-12-13 Thread Aaron Brady
Hi, I am writing a C process and I want to read data from a file that I write to in Python. I'm creating a pipe in Python, passing it to the C process, and calling '_read'. It gives me error 9, bad file number. Python code: import subprocess as s, os r, w= os.pipe( ) os.write( w, 'abcdefghij\n

Re: subprocess to C program

2008-12-13 Thread MRAB
Aaron Brady wrote: Hi, I am writing a C process and I want to read data from a file that I write to in Python. I'm creating a pipe in Python, passing it to the C process, and calling '_read'. It gives me error 9, bad file number. Python code: import subprocess as s, os r, w= os.pipe( ) os.wr

Re: subprocess to C program

2008-12-13 Thread Grant Edwards
On 2008-12-14, MRAB wrote: >> I am writing a C process and I want to read data from a file that I >> write to in Python. I'm creating a pipe in Python, passing it to the >> C process, and calling '_read'. It gives me error 9, bad file number. >> >> Python code: >> >> import subprocess as s, o

1 or 1/0 doesn't raise an exception

2008-12-13 Thread Daniel Fetchinson
Is it a feature that 1 or 1/0 returns 1 and doesn't raise a ZeroDivisionError? If so, what's the rationale? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Wojciech Muła
"Daniel Fetchinson" wrote: > Is it a feature that > > 1 or 1/0 > > returns 1 and doesn't raise a ZeroDivisionError? If so, what's the rationale? See: http://en.wikipedia.org/wiki/Short-circuit_evaluation -- http://mail.python.org/mailman/listinfo/python-list

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Tim Chase
Is it a feature that 1 or 1/0 returns 1 and doesn't raise a ZeroDivisionError? If so, what's the rationale? Yes, it's a feature: http://en.wikipedia.org/wiki/Short-circuit_evaluation When you have "True or False", you know it's true by the time you've got the first piece, so there's no need

Re: Bidirectional Networking

2008-12-13 Thread Brian Allen Vanderburg II
man...@gmail.com wrote: On Dec 13, 11:13 pm, Bryan Olson wrote: Software firewalls will often simply refuse incoming connections. The basic protection of the garden-variety home router comes from "network address translation" (NAT), in which case TCP connections initiated from the inside wil

Re: PyQt: Pulling Abstract Item Data from Mime Data using Drag and Drop.

2008-12-13 Thread Mudcat
On Dec 12, 6:17 pm, David Boddie wrote: > That's correct, retrieveData() is a protected function in C++ and the > QMimeData object was created by the framework, not you, in this case. Ah, well that explains it. Figured as much but was hoping maybe I was trying to access it incorrectly. > You co

Re: subprocess to C program

2008-12-13 Thread Aaron Brady
On Dec 13, 7:51 pm, Grant Edwards wrote: > On 2008-12-14, MRAB wrote: > > > > >> I am writing a C process and I want to read data from a file that I > >> write to in Python.  I'm creating a pipe in Python, passing it to the > >> C process, and calling '_read'.  It gives me error 9, bad file numbe

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread r
These are just the kind of things that make Python so beautiful ;) Thanks Guido! -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess to C program

2008-12-13 Thread MRAB
Aaron Brady wrote: On Dec 13, 7:51 pm, Grant Edwards wrote: On 2008-12-14, MRAB wrote: I am writing a C process and I want to read data from a file that I write to in Python. I'm creating a pipe in Python, passing it to the C process, and calling '_read'. It gives me error 9, bad file nu

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Steven D'Aprano
On Sat, 13 Dec 2008 19:17:41 +, Duncan Booth wrote: > I think you must have fallen asleep during CS101. The lower bound for > sorting where you make a two way branch at each step is O(n * log_2 n), > but if you can choose between k possible orderings in a single > comparison you can get O(n *

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Benjamin Kaplan
Not that I'm against promoting Python, but most languages have support for short circuit evaluation. That's why you usually use && and || in C, C++, C# and Java- & and | will always evaluate both sides. Short circuit evaluation is what allows you to write things like "if foo is not None and foo.isT

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
feba wrote: This is what I have so far. better? worse? Much better. I didn't check if it works. But you need to figure out a way to give up on your reliance on global variables. They will end up stifling you in the long run when you move to substantial projects. Also, you should start movin

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: Be assured that it takes on special intelligence to write unintelligible I meant "*no* special intelligence". -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Lie Ryan
On Sat, 13 Dec 2008 14:09:04 -0800, John Machin wrote: > On Dec 14, 8:07 am, "Chris Rebert" wrote: >> On Sat, Dec 13, 2008 at 12:28 PM, John Machin >> wrote: >> >> > Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit >> > (Intel)] on win32 >> > Type "help", "copyright", "credits

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Daniel Fetchinson
>> Is it a feature that >> >> 1 or 1/0 >> >> returns 1 and doesn't raise a ZeroDivisionError? If so, what's the >> rationale? > > Yes, it's a feature: > > http://en.wikipedia.org/wiki/Short-circuit_evaluation > > When you have "True or False", you know it's true by the time > you've got the first p

Error with SOAPpy

2008-12-13 Thread Amit Goyal
Hi All, I am new to Python and was trying the sample code on Dive into Python for WSDL. Below is the error I get. Traceback (most recent call last): File "", line 4, in -toplevel- print 'Light sensor value: ' + server._ns(namespace).readLSpercent (int_1 = "1") File "c:\Python24\Lib\site-p

Re: File names, character sets and Unicode

2008-12-13 Thread Дамјан Георгиевски
> In a nutshell, this is likely to cause pain until all file systems are > standardized on a particular encoding of Unicode. Probably only about > another fifteen years to go ... well, most Linux distros are defaulting to a UTF-8 locale now, the exception beeing Gentoo&similar that expect the use

subprocess to pipe through several processes?

2008-12-13 Thread Neal Becker
How would I use suprocess to do the equivalent of: cat - | program_a | program_b -- http://mail.python.org/mailman/listinfo/python-list

Re: Bidirectional Networking

2008-12-13 Thread Gabriel Genellina
En Sat, 13 Dec 2008 13:03:17 -0200, Emanuele D'Arrigo escribió: On Dec 12, 9:04 pm, "Gabriel Genellina" wrote: If you're using 2.5 or older, override serve_forever: def serve_forever(self): while not getattr(self, 'quit', False): self.handle_request() and set the

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Mark Tolonen
"John Machin" wrote in message news:a8cd683f-853d-4665-bee4-7a0bdb841...@c36g2000prc.googlegroups.com... On Dec 14, 9:20 am, "Martin v. Löwis" wrote: > >> This is intended behavior. > > > I see. That means that the behaviour in Python 1.6 to 2.6 (i.e. > > encoding the text using the repr() fu

Re: Error with SOAPpy

2008-12-13 Thread Jeremiah Dodds
On Sat, Dec 13, 2008 at 10:54 PM, Amit Goyal wrote: > Hi All, > > I am new to Python and was trying the sample code on Dive into Python > for WSDL. Below is the error I get. > > Traceback (most recent call last): > File "", line 4, in -toplevel- >print 'Light sensor value: ' + server._ns(nam

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Benjamin Kaplan
On Sat, Dec 13, 2008 at 10:49 PM, Daniel Fetchinson < fetchin...@googlemail.com> wrote: > >> Is it a feature that > >> > >> 1 or 1/0 > >> > >> returns 1 and doesn't raise a ZeroDivisionError? If so, what's the > >> rationale? > > > > Yes, it's a feature: > > > > http://en.wikipedia.org/wiki/Short-

Re: Bidrectional Subprocess Communication

2008-12-13 Thread Gabriel Genellina
En Sat, 13 Dec 2008 18:19:29 -0200, Emanuele D'Arrigo escribió: I'm trying to replicate the positive results of the Client/Server scripts from the thread "Bidirectional Networking", but this time using a Process/SubProcess architecture. The SubProcess, acting as a server, is working just fin

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-13 Thread Martin v. Löwis
> "Sure" as in "sure, it was not intended behaviour"? It was intended behavior, and still is in 3.0. >> This behavior has not changed. It still uses repr(). >> >> Of course, the string type has changed in 3.0, and now uses a different >> definition of repr. > > So was the above-reported non-cras

Re: curses and refreshing problem

2008-12-13 Thread Carl Banks
On Dec 13, 2:29 pm, Karlo Lozovina <_kar...@_mosor.net_> wrote: > Hi, I'm trying to implement text output interface, something similar to > wget, using curses module. There are just two things I can't find out how > to do: prevent curses from clearing the terminal when starting my program, > and le

Re: XMPP xmpppy - User Authorization

2008-12-13 Thread Henson
In my own bot, using the latest xmpppy, I've been printing everything going to the message handler to the screen. I've yet to see a 'subscribe' string. Has this changed? James Mills wrote: > On Wed, Nov 5, 2008 at 11:28 AM, James Mills > wrote: > > Can anyone shed any light on how I might > >

the official way of printing unicode strings

2008-12-13 Thread Piotr Sobolewski
Hello, in Python (contrary to Perl, for instance) there is one way to do common tasks. Could somebody explain me what is the official python way of printing unicode strings? I tried to do this such way: s = u"Stanisław Lem" print u.encode('utf-8') This works, but is very cumbersome. Then I tried

  1   2   >