Re: ctypes error

2010-01-15 Thread Dave Angel
>Gib Bogle wrote: >>I have a simple demo program (on Windows XP) that uses the ctypes module to load a DLL. >>This program works as expected with Python 2.5.4, but fails with Python 2.6.4 (on a different >> machine, each machine has only one Python version installed), with these messages: >>

Re: The answer

2010-01-18 Thread Dave Angel
Jive Dadson wrote: alex23 wrote: > > Actually, if you're using Python 2.6+/3.x, you can effectively skip > steps 1-5, as these versions now support user site-packages. > > Rather than create a Module folder and modify your PYTHONPATH, add (if > it doesn't exist already) the following folder: >

Re: Performance of lists vs. list comprehensions

2010-01-20 Thread Dave Angel
Steven D'Aprano wrote: A million items is not a lot of data. Depending on the size of each object, that might be as little as 4 MB of data: L = ['' for _ in xrange(10**6)] sys.getsizeof(L) 4348732 Note that this sys.getsizeof() is only saying the size of the list, not the size

Re: Symbols as parameters?

2010-01-21 Thread Dave Angel
Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction): ... If direction can only be "up", "down", "left" or "right", you can solve this by passing strings,

Re: Create object name from string value?

2010-01-21 Thread Dave Angel
Gnarlodious wrote: On Jan 20, 10:35 pm, Steven D'Aprano wrote: That's the wrong way to handle the problem. Named objects are only useful if you know the name of the object when writing the code. Otherwise, how do you know what name to use in the code? Thank you for the help. I am gath

Re: Symbols as parameters?

2010-01-22 Thread Dave Angel
Roald de Vries wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction): ... If direction can only be "up", "dow

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. disp

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted,

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Steven D'Aprano wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sor

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Dave Angel
Steve Howell wrote: On Jan 22, 12:40 pm, Christian Heimes wrote: Steve Howell wrote: Is that really true in CPython? It seems like you could advance the pointer instead of shifting all the elements. It would create some nuances with respect to reclaiming the memory, but it seems like

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Dave Angel
Arnaud Delobelle wrote: Steve Howell writes: On Jan 22, 12:14 pm, Chris Rebert wrote: I made the comment you quoted. In CPython, it is O(n) to delete/insert an element at the start of the list - I know it because I looked at the implementation a while ago. This is why collections.

Re: ISO module for binomial coefficients, etc.

2010-01-24 Thread Dave Angel
kj wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorial

Re: ISO module for binomial coefficients, etc.

2010-01-24 Thread Dave Angel
Alf P. Steinbach wrote: * Dave Angel: kj wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm l

Re: For loop searching takes too long!

2010-01-28 Thread Dave Angel
elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm using a list of lists, rather than a list of tuples

Re: For loop searching takes too long!

2010-01-28 Thread Dave Angel
Steve Holden wrote: Dave Angel wrote: elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks some

Re: Sleep timer but still responsive?

2010-01-30 Thread Dave Angel
JohnnyFive wrote: On Jan 29, 9:33 am, Andreas Tawn wrote: On Jan 28, 4:55 pm, "Gabriel Genellina" wrote: Please provide more details. What do you want your program to do while sleeping? What kind of actions do you want a response to? Do you have a GUI? A curses-b

Re: Microsoft Office Word and Python (Win XP)

2010-01-30 Thread Dave Angel
peskar.m...@hotmail.com wrote: 21 days has passed and still noone is willing to help :-( ch /willing/able/ I wouldn't say no-one, even then, since there were at least 10 messages in the thread on the 19th and 20th. Presumably they weren't all from you. If you were doing this to text fil

Re: Still too slow

2010-01-30 Thread Dave Angel
John Posner wrote: On 1/30/2010 6:08 PM, elsa wrote: Hello again, Thanks for the tips r.e random.ranint(). This improved matters somewhat, however my program is still too slow. If anyone has any further tips on how to speed it up, they would be much appreciated! So, I'm calling evolve(L,limit)

Re: How to control I/O buffering besides -u?

2009-09-26 Thread Dave Angel
kj wrote: Is there any way to specify unbuffered I/O from *within* the code (rather than via the command-line -u flag)? TIA! kynn When creating a file object, specify a buffer size of zero. I don't know how to change the buffering of a file object that's already been created, as stdin, s

Re: Most "active" coroutine library project?

2009-09-26 Thread Dave Angel
Dennis Lee Bieber wrote: On Fri, 25 Sep 2009 14:22:51 + (UTC), Grant Edwards declaimed the following in gmane.comp.python.general: EXX accomplised much of the context switch operation. I don't remember how much RAM was available, but it wasn't much... Zilog Z80... as wit

Re: can i use the browser to show the result of python

2009-09-26 Thread Dave Angel
Hacken wrote: On Sep 25, 6:27 pm, Dave Angel wrote: Hacken wrote: I have write some python script i want to use browser(IE or FF) to call it, an show the returns! how to? You don't say much about your environment, nor the nature of your script. So my res

Re: unexplainable python

2009-09-26 Thread Dave Angel
dads wrote: When creating a script that converts digits to words I've come across some unexplainable python. The script works fine until I use a 5 digit number and get a 'IndexError: string index out of range'. After looking into it and adding some print calls, it looks like a variable changes fo

Re: Using String for new List name

2009-09-28 Thread Dave Angel
Scott wrote: Thank you fine folks for getting back with your answers! So down the road I do dictname[line42].append("new stuff"). (or [var] if I'm looping through the dict) Nope, you still haven't gotten it. Of course, I really don't know where you're going wrong, since you didn't use the

Re: module path?

2009-09-28 Thread Dave Angel
akonsu wrote: hello, is there a way to determine the file location of a loaded module? assuming it is not built in. import settings print settings produces: i would like to get to this path somehow other than by parsing the string representation of the module. is there a property on types.Mo

Re: different behaviour for user defined exception with attribute args

2009-09-29 Thread Dave Angel
Visco Shaun wrote: Hi all For an exception defined as below class OptionError(Exception): def __init__(self, args): self.args = args def __str__(self): return repr(self.v) an iteration is happening when the exception is raised What is self.v intended to produce?

Re: Re: variable scope

2009-09-29 Thread Dave Angel
Bruno Desthuilliers wrote: (snip) Joel Juvenal Rivera Rivera wrote: Hi i was playing around with my code the i realize of this ### _uno__a = 1 class uno(): __a = 2 def __init__(self): print __a uno() ### and prints 1 I beg to disagree. The probl

Re: How to pass a global variable to a module?

2009-09-29 Thread Dave Angel
Mars creature wrote: I can understand the point that global variables tends to mess up programs. Assume that I have 10 parameters need to pass to the function. If these parameters are fixed, I can use another module to store these 10 parameters, and import to the module, as suggested by jean-mi

Re: unicode issue

2009-09-30 Thread Dave Angel
gentlestone wrote: Why don't work this code on Python 2.6? Or how can I do this job? _MAP = # LATIN u'À': 'A', u'Á': 'A', u'Â': 'A', u'Ã': 'A', u'Ä': 'A', u'Å': 'A', u'Æ': 'AE', u'Ç':'C', u'È': 'E', u'É': 'E', u'Ê': 'E', u'Ë': 'E', u'Ì': 'I', u'Í': 'I', u'Î': 'I', u'Ï': 'I', u'Ð'

Re: unicode issue

2009-09-30 Thread Dave Angel
Piet van Oostrum wrote: Dave Angel (DA) wrote: DA> Works for me: DA> rrr = downcode(u"Žabovitá zmiešaná kaša") DA> print repr(rrr) DA> print rrr DA> prints out: DA> u'Zabovita zmiesana kasa' DA> Zabovit

Re: unicode issue

2009-09-30 Thread Dave Angel
Piet van Oostrum wrote: Dave Angel (DA) wrote: [snip] DA> Thanks for the correction. What I meant by "works for me" is that the DA> single example in the docstring translated okay. But I do have a lot to DA> learn about using Unicode in sources,

Re: Most "active" coroutine library project?

2009-09-30 Thread Dave Angel
Grant Edwards wrote: On 2009-09-30, Rhodri James wrote: On Mon, 28 Sep 2009 15:44:48 +0100, Grant Edwards wrote: $10 is pretty expensive for a lot of applications. I bet that processor also uses a lot of power and takes up a lot of board space. If you've only got $2-$3 in the mone

Re: unicode issue

2009-10-01 Thread Dave Angel
gentlestone wrote: save in utf-8 the coding declaration also has to be utf-8 ok, I understand, but what's the problem? Unfortunately seems to be the Python interactive mode doesn't have unicode support. It recognize the latin-1 encoding only. So I have 2 options, how to write doctest: 1.

Re: Python and lost files

2009-10-02 Thread Dave Angel
Carl Banks wrote: On Sep 30, 11:35 pm, "Timothy W. Grove" wrote: Recently I purchased some software to recover some files which I had lost. (A python project, incidentally! Yes, I should have kept better backups!) They were nowhere to found in the file system, nor in the recycle bin, but thi

Re: Threaded GUI slowing method execution?

2009-10-02 Thread Dave Angel
Aaron Hoover wrote: I have a wx GUI application that connects to a serial port in a separate thread, reads from the port, and then is supposed to put the data it finds into a queue to be used by the main GUI thread. Generally speaking, it's working as expected. However, one method (that's pa

Re: Threaded GUI slowing method execution?

2009-10-02 Thread Dave Angel
(you responded off-list, which isn't the way these mailing lists work. So I'm pasting your message back to the list, with my response at the end) Aaron Hoover wrote: But as soon as you have two threads doing "busy work," instead of them getting 50% each, the threading overhead goes way up,

Re: creating class objects inside methods

2009-10-04 Thread Dave Angel
horos11 wrote: Carl, Thanks for the info, but a couple of points: 1. it wasn't meant to be production code, simply a way to teach python. 2. this should either be a compile time or a runtime error. 'Actions at a distance' like this are deadly both to productivity and to correctness -

Re: WMI remote call in python script to create process on remote windows computer

2009-10-06 Thread Dave Angel
davidj411 wrote: import win32com.client computer = "server" strUser = "server\user_name" strPassword ="my_password" objSWbemLocator = win32com.client.Dispatch ("WbemScripting.SWbemLocator") objSWbemServices = objSWbemLocator.ConnectServer(computer, "root \cimv2",strUser,strPassword) objCreateProc

Re: del an imported Class at EOF... why?

2009-10-06 Thread Dave Angel
Carl Banks wrote: On Oct 6, 10:56 am, Ryan wrote: Good day all! I've just inherited a large amount of python code. After spending some time pour through the code, I've noticed that the original developer (who is no longer w/ the company) constantly deletes the imported classes at the end of

Re: package import dangers

2009-10-06 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 06 Oct 2009 18:42:16 +0200, Diez B. Roggisch wrote: The most common problem is that a file is used as module and as executable at the same time. Like this: --- test.py --- class Foo(object): pass if __name__ == "__main__": import test assert Foo

Re: bug with itertools.groupby?

2009-10-06 Thread Dave Angel
Kitlbast wrote: On Oct 7, 3:04 am, Raymond Hettinger wrote: On Oct 6, 4:06 pm, Kitlbast wrote: Hi there, the code below on Python 2.5.2: from itertools import groupby info_list = {'profile': 'http://somesite.com/profile1', 'account': 61L}, {'profile'

Re: package import dangers

2009-10-06 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 06 Oct 2009 21:44:35 -0400, Dave Angel wrote: I'm surprised to see you missed this. A module doesn't generally import itself, but it's an easy mistake for a circular dependency to develop among modules. Circular imports are alway

Re: WMI remote call in python script to create process on remote windows computer

2009-10-07 Thread Dave Angel
David Jackson wrote: ok, cut and pasted, but changed the username/password to protect the innocent. this is from interactive prompt. let me know if i am still not doing the slashes correctly please. i doubt authentication is the issue.; i can get pid information using WQL queries. objCreateProc.C

Re: Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread Dave Angel
bsneddon wrote: I saw an issue on winXP box not connected to internet yesterday, where i was running a script in the interactive window on PythonWin . I would modify the script save and import and was still running the old version. I did that several times with same result. I even renamed th

Re: Best way to handle changing list of class imports

2009-10-10 Thread Dave Angel
Scott Grant wrote: On Oct 10, 2:42 pm, "Diez B. Roggisch" wrote: Scott Grant schrieb: Hi there, I'd like to set up a framework in which I can add or remove new classes of a given expected subclass to my package, and have the system load that set at runtime and be able to use

Re: code in a module is executed twice (cyclic import problems) ?

2009-10-11 Thread Dave Angel
(please don't top-post. Put your reply *after* the message you're quoting.) Stef Mientki wrote: thanks very much Stephen, This is the first time I become aware of the difference between script and module !! Starting with the wrong book "Learning Python" second edition, from Lutz and Ascher,

Re: postprocessing in os.walk

2009-10-12 Thread Dave Angel
kj wrote: Perl's directory tree traversal facility is provided by the function find of the File::Find module. This function accepts an optional callback, called postprocess, that gets invoked "just before leaving the currently processed directory." The documentation goes on to say "This hook is

Re: code in a module is executed twice (cyclic import problems) ?

2009-10-12 Thread Dave Angel
greg wrote: Dave Angel wrote: The point you should get from that link is "Don't do circular imports. Ever." No, I would say the lesson to be learned from this is "don't use the same file as both a main script and an imported module". I would create another f

Re: deepcopy of class inherited from Thread

2009-10-12 Thread Dave Angel
VYAS ASHISH M-NTB837 wrote: Dear All I am running this piece of code: from threading import Thread import copy class Ashish(Thread): def __init__(self, i): Thread.__init__(self) self.foo = i def run(self): print (self, self.foo) d= Ashish(4) e = copy.de

Re: does anyone know how to use libjeg from within memory in python

2009-10-13 Thread Dave Angel
Chris Colbert wrote: Say I use python to talk to a wireless webcamera that delivers images via http requests. I request an image and read it into a buffer, but the image is in jpeg format. I would like to convert this to a simple RGB format buffer to pass to numpy. Has anyone managed this using

Re: postprocessing in os.walk

2009-10-13 Thread Dave Angel
Peter Otten wrote: kj wrote: In Dave Angel writes: kj wrote: Perl's directory tree traversal facility is provided by the function find of the File::Find module. This function accepts an optional callback, called postprocess, that gets invoked "just before l

Re: efficient running median

2009-10-13 Thread Dave Angel
Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is unfortunately too slow as my sliding wi

Re: setting variables in the local namespace

2009-10-13 Thread Dave Angel
Mick Krippendorf wrote: Yes, and, uh, yes. "locals()['foo'] = bar" works in that it does the same thing as "foo = bar". So why don't you write that instead? Mick. I wouldn't expect it to do the same thing at all, and it doesn't, at least not in Python 2.6.2. It may store the "bar" som

Re: Re: for loop: range() result has too many items

2009-10-13 Thread Dave Angel
Andre Engels wrote: On Tue, Oct 13, 2009 at 11:55 PM, Andre Engels wrote: for i in range(sys.maxint): if i % 100 =0: print i Grmbl cut-and-paste error... I meant of course: for i in xrange(sys.maxint): if i % 100 =0: print i What version of Python gives a

Re: Writing to function arguments during execution

2009-10-14 Thread Dave Angel
John O'Hagan wrote: Thanks, sockets are the way to go for this and surprisingly easy to use once you get your head around them. I tried Rhodri's suggested approach but for now I used the original terminal for both starting the program and entering new options (still via raw_input) and a new t

Re: the usage of 'yield' keyword

2009-10-14 Thread Dave Angel
Peng Yu wrote: http://docs.python.org/reference/simple_stmts.html#grammar-token-yield_stmt The explanation of yield is not clear to me, as I don't know what a generator is. I see the following example using 'yield'. Could somebody explain how 'yield' works in this example? Thank you! def brange

Re: win32com.client import problem

2009-10-14 Thread Dave Angel
Threader Slash wrote: Hi Everybody, I have 2 imports: import pythoncom from win32com.client import Dispatch if I run it on my Python 2.6 Console, it works nicely. However, when I go to Eclipse IDE, open a project, open a main.py file, and try run, it gives the error: import pythoncom ImportEr

Re: Colour sampling

2009-10-15 Thread Dave Angel
Anthra Norell wrote: Dylan Palmboom wrote: Does anyone know what python libraries are available to do the following: 1. I would like to take a photograph of an object with a colour. In this case, it is a sheet of sponge. 2. Feed this image into a function in a python library and let the func

Re: the usage of 'yield' keyword

2009-10-15 Thread Dave Angel
Tim Golden wrote: Dave Angel wrote: def find(root): for pdf in os.walk(root, topdown=False): for file in pdf[2]: yield os.path.join(pdf[0],file) At the risk of nitpicking, I think that a modicum of tuple-unpacking would aid readability here: for dirpath

Re: set using alternative hash function?

2009-10-16 Thread Dave Angel
Austin Bingham wrote: On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman wrote: Austin Bingham wrote: I'm feeling really dense about now... What am I missing? What you're missing is the entire discussion up to this point. I was looking for a way to use an alternative uniqueness criteria in

Re: putchar(8)

2009-10-16 Thread Dave Angel
Jason Tackaberry wrote: On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). print '\x08' or: print chr(8) If I recall correctly, putchar() tak

Re: print()

2009-10-16 Thread Dave Angel
mattia wrote: Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! What the other responses (so far) didn't address is your comment about "prints the number of characters."

Re: Rename file if it exists.

2009-10-16 Thread Dave Angel
Stephen Reese wrote: The script is working and appending the date to newly uploaded files but it is not adding the count? Any recommendations? Is the problem due to os.path.isfile(fn): being just the file name and not the full path? Thanks. # strip leading path from file name to avoid

Re: putchar(8)

2009-10-17 Thread Dave Angel
Dave Angel wrote: Jason Tackaberry wrote: On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). print '\x08' or: print chr(8) I

Re: print()

2009-10-17 Thread Dave Angel
Grant Edwards wrote: On 2009-10-17, Dave Angel wrote: Except sys.stdout.write("hello") doesn't return 5. It returns None. I don't know what the OP is talking about when he says "prints the number of characters": You're right of course, I should ha

Re: zipfile extracting png files corrupt

2009-10-17 Thread Dave Angel
marks542...@yahoo.com wrote: Hi, I am using the zipfile in Python 2.4 to extract files from existing zips. It appears to work but the files extracted are corrupt. Have you done any analysis to see in what sense they are corrupt? For example, do text files work, but not binary ones? If the f

Re: print()

2009-10-17 Thread Dave Angel
mattia wrote: Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! Another question (always py3). How can I print

Re: print()

2009-10-17 Thread Dave Angel
mattia wrote: Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel declaimed the following in gmane.comp.python.general: You're presumably testing this in the interpreter, which prints extra stuff. In particula

Re: print()

2009-10-17 Thread Dave Angel
Lie Ryan wrote: mattia wrote: Another question (always py3). How can I print only the first number after the comma of a division? e.g. print(8/3) --> 2.667 I just want 2.6 (or 2.66) Are you sure you don't want that to be 2.7 or 2.67? Then you can use: n = int(n * 10**2) / 10**2 else i

Re: restriction on sum: intentional bug?

2009-10-18 Thread Dave Angel
Dieter Maurer wrote: Christian Heimes writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use

Re: weekdays in range

2009-10-18 Thread Dave Angel
Jive Dadson wrote: Wow. It's a danged tutorial. Thanks again. Take a break. Ben Finney's method is a very good approach, and an experienced Python programmer would consider it straightforward. But I have to ask whether the range of dates you might be considering could be large. For ex

Re: print()

2009-10-19 Thread Dave Angel
Gabriel Genellina wrote: but the new str.format() originally suggested by Dave Angel is better: s = "{0:03.02f}% done".format(100.0-100.0*(size/tot)) (BTW, why 03.02f? The output will always have at least 4 chars, so 03 doesn't mean anything... Maybe you want {0:06.2f} (thre

Re: strange behaviour of colon within string

2009-10-19 Thread Dave Angel
khany wrote: On 19 Oct, 14:44, StarWing wrote: On Oct 19, 9:15 pm, khany wrote: On 19 Oct, 13:44, khany wrote: however it fails to create the string UNLESS i remove the colon (:) in the http section. i tried to substitute it with chr(58) but it errors the same

Re: classes riddle

2009-10-19 Thread Dave Angel
inhahe wrote: Can somebody clear this up for me? -- Class B(A): def __init__(self, a) A.__init__(a) self.a = a a = A() ba = B(a) bc = B(a) bd = B(a) -- I'm not sure what A.__init__ here does. I would think its __init__ is designed specifically to run once for any given object.. so i'm no

Re: Struct on on x86_64 mac os x

2009-10-21 Thread Dave Angel
Mark Dickinson wrote: On Oct 20, 10:51 pm, Tommy Grav wrote: I have created a binary file that saves this struct from some C code: struct recOneData { char label[3][84]; char constName[400][6]; double timeData[3]; long int numConst; double AU;

Re: Windows file paths, again

2009-10-21 Thread Dave Angel
Dan Guido wrote: Hi Diez, The source of the string literals is ConfigParser, so I can't just mark them with an 'r'. config =onfigParser.RawConfigParser() config.read(filename) crazyfilepath =onfig.get(name, "ImagePath") normalfilepath =ormalize_path(crazyfilepath) The ultimate origin of the st

Re: Windows file paths, again

2009-10-21 Thread Dave Angel
Dan Guido wrote: This doesn't give me quite the results I expected, so I'll have to take a closer look at my project as a whole tomorrow. The test cases clearly show the need for all the fancy parsing I'm doing on the path though. Looks like I'll return to this tomorrow and post an update as app

Help with code = Extract numerical value to variable

2009-10-23 Thread Dave Angel
Steve wrote: Sorry I'm not being clear Input** sold: 16 sold: 20 sold: 2 sold: 0 sold: 7 0 sold null Output 16 20 2 0 0 7 0 0 0 0 Since you're looking for only digits, simply make a string containing all characters that aren't digits. Now, loop through the file and use

Re: problem with pythonw.exe

2009-10-23 Thread Dave Angel
Martin Shaw wrote: Hi, I have a tkinter application running on my windows xp work machine and I am attempting to stop the console from appearing when the application runs. I've researched around and the way to do this appears to be to use pythonw.exe instead of python.exe. However when I try to

Re: Python 3.1.1 bytes decode with replace bug

2009-10-25 Thread Dave Angel
Joe wrote: For the reason BK explained, the important difference is that I ran in the IDLE shell, which handles screen printing of unicode better ;-) Something still does not seem right here to me. In the example above the bytes were decoded to 'UTF-8' with the *nope* you're decoding

Re: Listing variables

2009-10-25 Thread Dave Angel
vsoler wrote: Say that a have: # file test.py a=7 At the prompt: import test dir() I would like to see the variables created in the test namespace. However, variable "a" does not appear in the list, only "test". Since I know that var "a" is reachable from the prompt by means of test.a, how ca

Re: Strange behavior related to value / reference

2009-10-28 Thread Dave Angel
Mark Dickinson wrote: On Oct 28, 8:24 am, Lambda wrote: Thank you! Following is my final code: Looks good, but are you sure about that word 'final'? ;-) def matrix_power(m, n): """ Raise 2x2 matrix m to nth power. """ if n =0: return [[1, 0], [0, 1]] x =atrix_power(m,

Re: Reference values for exec

2009-10-28 Thread Dave Angel
Garito wrote: Hi! I'm trying to use exec in a recursive way but I have a problem When I read the manual I understand that the globals and the locals are passed by reference but if I try to use it in a recursive way the new values added in a step are not passed to the next one Could someone poin

Re: Reference values for exec

2009-10-28 Thread Dave Angel
em 2 questions came to my mind: 1.- How can I execute code from files in the filesystem? (I choose exec for that) That's what import is for. Or __import__() if you need more flexibility. 2.- If exec is my only option: how can I use a common stack for them? Thanks 2009/10/28

Re: how to zip a StringIO object?

2009-10-28 Thread Dave Angel
Nagy Viktor wrote: Hi, I try to run the following code: def generate_zip(object_list, template): result = StringIO.StringIO() zipped = zipfile.ZipFile(result, "w") for object in object_list: pdf = generate_pdf(object, template) if not pdf: raise IOError("

Re: Problem embedding Python.

2009-10-29 Thread Dave Angel
Brandon Keown wrote: On Oct 27, 7:48 pm, "Gabriel Genellina" wrote: Now that you've solved your problem, revise your conclusion. A file without a path *is* searched in the current working directory - but that directory may not be the one you think it is. -- Gabriel Genellina I'm not

Re: Python 2.6 Global Variables

2009-10-29 Thread Dave Angel
AK Eric wrote: 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. Isn't that __main__? import __main__ __main__.foo = "asdfasdf" print foo # asdfasdf Not advocating, but it does serve the purpose. Good that you're not advocating it,

Re: Recommended number of threads? (in CPython)

2009-10-29 Thread Dave Angel
Paul Rubin wrote: Neil Hodgson writes: If you are running on a 32-bit environment, it is common to run out of address space with many threads. Each thread allocates a stack and this allocation may be as large as 10 Megabytes on Linux. I'm sure it's smaller than that under most cir

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Dave Angel
metal wrote: Consider the following: class Parent: def some_method(self): return Parent(...) class Child: def some_method(self): ... return Parent.some_method(self) ##

Re: Problem embedding Python.

2009-10-30 Thread Dave Angel
Dave Angel wrote: Brandon Keown wrote: On Oct 27, 7:48 pm, "Gabriel Genellina" wrote: Now that you've solved your problem, revise your conclusion. A file without a path *is* searched in the current working directory - but that directory may not be the one you think it

Re: Modify dict/set during iteration?

2009-10-30 Thread Dave Angel
metal wrote: Steven D'Aprano wrote: On Thu, 29 Oct 2009 19:02:01 -0700, metal wrote: I used this quickndirty way, any good idea to solve this problem? It's not a problem that wants solving, it's a feature that wants paying attention to. As a general rule, you shouldn't modify d

Re: Python 2.6 Global Variables

2009-10-30 Thread Dave Angel
Gabriel Genellina wrote: En Fri, 30 Oct 2009 00:29:27 -0300, Steven D'Aprano escribió: On Thu, 29 Oct 2009 10:31:03 -0700, AK Eric wrote: 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. It isn't a neat trick anymore once you realize the

Re: How to avoid certain directories when using os.walk?

2009-10-30 Thread Dave Angel
Chris Rebert wrote: On Thu, Oct 29, 2009 at 9:53 PM, Peng Yu wrote: I don't see a way to avoid walking over directories of certain names with os.walk. For example, I don't want os.walk return files whose path include '/backup/'. Is there a way to do so? Otherwise, maybe I will have to make m

Re: import problem in tkinter

2009-10-30 Thread Dave Angel
Jebegnana das wrote: import _tkinter # If this fails your Python may not be configured for Tk I'm using python3 in linux. In windows tkinter is working fine but in mandriva linux spring 2009 it fails to import. Can you please tell me step-by-step on how to fix this issue? In python3.1 home page

Re: Are *.pyd's universal?

2009-10-30 Thread Dave Angel
Carl Banks wrote: On Oct 29, 9:10 pm, Lawrence D'Oliveiro wrote: In message , Christian Heimes wrote: Lawrence D'Oliveiro schrieb: In message , Christian Heimes wrote: On Linux and several other Unices the suffix is .so and not .pyd. Why is that? Or conve

Re: How to avoid certain directories when using os.walk?

2009-10-30 Thread Dave Angel
Sean DiZazzo wrote: On Oct 29, 10:17 pm, Chris Rebert wrote: On Thu, Oct 29, 2009 at 9:53 PM, Peng Yu wrote: I don't see a way to avoid walking over directories of certain names with os.walk. For example, I don't want os.walk return files whose path include '/backup/'. Is there a way

Re: How can module determine its own path?

2009-10-30 Thread Dave Angel
Stef Mientki wrote: Robert Kern wrote: On 2009-10-30 12:19 PM, kj wrote: How can a module determine the path of the file that defines it? (Note that this is, in the general case, different from sys.argv[0].) __file__ but for modules launched with execfile, __file__ doesn't exists. cheers,

Re: problem with read() write()

2009-10-31 Thread Dave Angel
Zeynel wrote: On Oct 31, 9:55 am, "Alf P. Steinbach" wrote: * Zeynel: On Oct 31, 9:23 am, "Alf P. Steinbach" wrote: * Zeynel: Hello, I've been studying the official tutorial, so far it's been fun, but today I ran into a problem with the write(). So, I open the f

Re: How to import only one module in a package when the package __init__.py has already imports the modules?

2009-10-31 Thread Dave Angel
Peng Yu wrote: On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland wrote: On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote: On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern wrote: [ snip ] I know that multiple classes or functions are typically defined in one file (i.e. mod

Re: stdin in embedded python

2009-11-01 Thread Dave Angel
KillSwitch wrote: I have a C++ program, with a GUI, into which I have embedded python. I have made several python functions in C++, one of which I use to override the normal stdout and stderr so that they print to a text box of my GUI. One thing I cannot think of how to do is to redefine stdin so

Re: stdin in embedded python

2009-11-01 Thread Dave Angel
Gabriel Genellina wrote: En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch escribió: On Nov 1, 5:34 am, Dave Angel wrote: KillSwitch wrote: > I have a C++ program, with a GUI, into which I have embedded python. I > have made several python functions in C++, one of which I use to >

<    17   18   19   20   21   22   23   24   25   26   >