Re: str() and repr() question
adima schrieb: > str = DoTestTime(EachFile) ^^^ > print type(str) > for s in str: > print s > out.write(str(s)) ^^^ > Where is the problem here? > Thanks in advance. > You have overwritten the built-in str function some lines above. Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: bitwise shift?
desktop schrieb: > I have found a code example with this loop. > > for k in range(10, 25): > n = 1 << k; > > > I have never read Python before but is it correct that 1 get multiplied > with the numbers 10,11,12,12,...,25 assuming that 1 << k means "1 shift > left by k" which is the same as multiplying with k. 1 << n is a more efficient replacement for 2**n Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system('tar -c * | tar -C dst') ##Any other suggestions...
[EMAIL PROTECTED]: > Any suggestions on a different approach or fix? Check your commandline! The second command is wrong, -C is not valid as the only option, a command is missing. If you just want to archive files in a tarball try: "tar -c * > dst.tar" or take a look at Python's tarfile lib. Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: Catching a specific IO error
Tina I schrieb: > Now, this works but of course it catches every IOError, and I can not > figure out how to restrict it to only catch the "[Errno 2]"? There's an example that uses the error number: http://docs.python.org/tut/node10.html#SECTION001030 Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: [SQLite] Recommended wrapper?
It's all there: http://docs.python.org/lib/module-sqlite3.html Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: Authenticating clients and servers
Thomas Krüger schrieb: > Many protocols support an additional SSL/TLS-Layers (e.g. HTTP -> > HTTPS). There you can use SSL certificate authentication. It may > berequired to set up a small CA, but done right it is pretty secure. I missed the best: The Twisted framework has SSL authentication already implemented: http://twistedmatrix.com/ But there also more lightweigt implementations like httplib.HTTPSConnection (for clients) or pyopenssl Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: Authenticating clients and servers
Chaz Ginger schrieb: > I am writing a distributed server system using Python. I need to support > authentication and was wondering what approaches are available under > Python and what are the best practices. Well, there are many ways of client authentication. To narrow it down it would be nice if your tell us something about the protocol you are planning to use. Many protocols support an additional SSL/TLS-Layers (e.g. HTTP -> HTTPS). There you can use SSL certificate authentication. It may berequired to set up a small CA, but done right it is pretty secure. Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: THREADS use 100 % CPU all the time
[EMAIL PROTECTED] schrieb: > while (True): > pass > Does anyone know how to run this without consuming all CPU. Your while loop is taking all the CPU time. Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: Queue get timeout parameter question
Godzilla schrieb: > I have been using the queue module for a multithreaded environment and > things seem to work well... until we had a requirement for the > application to be able to time sync to the server. With the time sync, > it actually disorientated the timeout in the queue's get() method... > e.g. > > get(item, 2.0) > > After the time sync, say 15 seconds backward, the thread is sitting on > that get() method for a total of 17 seconds. We can only sync the > device once per day and the time can drift up to 15 seconds per day!! > I had tried to get around this problem by having a sleep(2) (sleep is > not local system time dependant) just before the get(), but that will > slow down the application too much. > > Anyone knows a solution to this problem or an alternative method? I was fixing a serious time drift problem on Linux lately. If your server runs on Linux I can give you some hints: - set the system clock - delete /etc/adjtime and resync system time and hardware time "hwclock --systohc" - on some distributions you may have to reboot - give it some time to see if it is still drifting - if only the system clocks drifts (see output of "hwclock; date") you may have a timer related kernel problem. This may help: * deactivate ACPI via kernel boot parameter * change timer frequency * try different setting for all timer related stuff like CONFIG_HPET_TIMER or CONFIG_X86_PM_TIMER Thomas -- sinature: http://nospam.nowire.org/signature_usenet.png -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?
人言落日是天涯,望极天涯不见家 schrieb: > Is there a simple function to generate a list like ['a', 'b', 'c', ... > 'z']? The range() just can generate the numeric list. There is: [ chr(i) for i in range(97, 123) ] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Crypto Suggestion/Help
Jimmy E Touma schrieb: > I need some advise on doing the following. I have a Linux application > that allows users to access it via a code (password). At the end of the > day, I gather a log of activities of the users and zip the file and > would like to encrypt it so that the users can not access it or tamper > with it. Only manager should. If I use a private/public key for doing so > I have to store the private key on my computer. What is a good way to > encrypt a file and have the key well hidden on the same computer? If you > have any other way to do, like MD5 or similar, please let me know. You don't need encryption, cryptographic hashes or Python. What you need are just the basic UNIX/Linux permissions. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does not my wx.html.HtmlWindow work?
[EMAIL PROTECTED] schrieb: > html.LoadPage(" > http://www.pythonthreads.com/articles/python/incorporating-into-wxpython-part-1.html";) Quickshot: There's a space at the start of your URI. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Using os.popen3() to get binary data
Christoph Krammer schrieb: > for image in images: > if (image[0:3] == 'GIF'): > (si, so, se) = os.popen3('giftopnm -image=all', 'b') > si.write(image) > frame = so.readlines() > > But with this code the script just hangs. When I interrupt the script, > I get the following error message: > Traceback (most recent call last): > File "/home/tiger/stock-spam/scripts/all_in_one.py", line 46, in ? > frames = so.readlines() > KeyboardInterrupt > close failed: [Errno 32] Broken pipe Just a try: use read() instead of readlines()! Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on MIPS
Lorenzo Mainardi schrieb: > I bought a very small embedded card, with a MIPS processor, running > Linux. So, I would to use Python on that; I checked on python.org, but I > did'nt find any release for this architecture. Could you help me? How about compiling it from source? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Chris Lasher schrieb: > why should we NOT be > placing classes in their own separate files? > > Thoughts, comments, and insight much appreciated, At first: if he really like it he can place every class in a single file. But there are some reasons why Python "allows" you to place many classes in one file: - It's (a little bit) faster, no additional file system lookup is needed. ;) - You can define a class in a class. Django, for example, uses this for it's data models. If you do this you are forced to have multiple classes in on file. Example: http://www.djangoproject.com/documentation/tutorial02/#make-the-poll-app-modifiable-in-the-admin See also: http://mail.python.org/pipermail/python-list/2006-December/418363.html Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about text in Python
Steve schrieb: > I've created a Python program that a user enteres one line of text which > will then create an acronym from that text. > > What I want to add to the program is the abilty to rerun this process > (where the user enteres another line of text) until the user has had > enough and enters a blank line which would then end the program. You can do this with a while loop. If the user enters a blank line you can break out of the loop: while true: (some code) if not line: break Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Web App Framework with PostgreSQL + fast + easy
Ben schrieb: > I'm looking for a web application framework with a good interface to > PostgreSQL. You may check out Django: http://www.djangoproject.com/ Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting a multidimensional array by multiple keys
Alex Martelli schrieb: > Thomas Krüger <[EMAIL PROTECTED]> wrote: >> def sorter(a, b): >> return cmp(a.id, b.id) >> >> obj_lst.sort(sorter) > > A MUCH better way to obtain exactly the same semantics would be: > > def getid(a): > return a.id > > obj_list.sort(key=getid) Frankly speaking the purpose of the example was to show how to pass a function as argument for the sort method. Your code may be more efficient but it explains something different. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting a multidimensional array by multiple keys
Rehceb Rotkiv schrieb: > can I sort a multidimensional array in Python by multiple sort keys? A > litte code sample would be nice! You can pass a function as argument to the sort method of a list. The function should take two arguments and return -1, 0 or 1 as comparison result. Just like the cmp function. This will objects in list obj_lst by their id attributes: def sorter(a, b): return cmp(a.id, b.id) obj_lst.sort(sorter) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system questions
Eric Price schrieb: > up = os.system("uptime") > How do I assign the output of "uptime" to the variable "up"? | >>> print os.system.__doc__ | system(command) -> exit_status | | Execute the command (a string) in a subshell. os.system returns the exitcode of the given command. To get the output try os.popen to os.popen4 or the commands lib. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
DE schrieb: > Hello, > > Here is what I do in C++ and can not right now in python : > > pushMatrix() > { > drawStuff(); > > pushMatrix(); > { > drawSomeOtherStuff() > } > popMatrix(); > } > popMatrix(); > > The curly brackets have no functional meaning but increase the > readability significantly. I want to be able to do the same thing in > python. Since curly brackets are not available and indenting without > an if or while conditional doesn't work, I have started to question if > this is possible in python at all. > > Any ideas ? I've been thinking about that for some minutes now and I have doubts that it will increase the readability. Maybe for you as you invented that style but not for others. There are a few standards for formatting C code and even this few have cause many discussions between developers. Python has one convention (defined in PEP 8) and the deeper you dive into the language the more you will like it. BTW: having one way to do it is one of the main ideas of Python's philosophy. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with class variables
Dag schrieb: > I have a problem which is probaly very simple to solve, but I can't > find a nice solution. > I have the following code > > class Test: > def __init__(self): > self.a=[1,2,3,4] > self.b=self.a > def swap(self): > self.a[0],self.a[3]=self.a[3],self.a[0] > def prnt(self): > print self.a > print self.b > c=Test() > c.swap() > c.prnt() > > which returns > [4,2,3,1] > [4,2,3,1] > > Now I understand why it is doing this, but it's not what I want. How to > I get it to return > [4,2,3,1] > [1,2,3,4] > > Dag Use a copy of self.a: self.b = self.a[:] Thomas -- http://mail.python.org/mailman/listinfo/python-list