Re: Code generator and visitor pattern

2010-07-15 Thread Matt McCredie
Karsten Wutzke web.de> writes: > So, what is the de facto method in Python to handle source code generation? Take a look at the NodeVisitor class in the ast module in python 2.6+. The visitor pattern is implemented in the python standard library. Matt -- http://mail.python.org/mailman/listi

Re: Namespace problem?

2010-07-01 Thread Matt McCredie
Josh English gmail.com> writes: > > I have a script that generates a report from a bunch of data I've been > collecting for the past year. I ran the script, successfully, for > several weeks on test runs and creating more detailed reports. > > Today (back from vacation) and the script doesn't w

Re: hex question

2010-06-25 Thread Matt McCredie
Sneaky Wombat gmail.com> writes: > > Why is python turning \x0a into a \n ? > > In [120]: h='\x0a\xa8\x19\x0b' > > In [121]: h > Out[121]: '\n\xa8\x19\x0b' > > I don't want this to happen, can I prevent it? 'h' is an ascii string. The ascii encoding for '\n' is the number(byte) 0x0A. When y

Re: string to list when the contents is a list

2010-02-17 Thread Matt McCredie
provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None. """ node = parse(text, mode='eval').body if not isinstance(node, List): raise ValueError('malformed string') def _convert(node): if isinstance(node, Str): return node.s raise ValueError('malformed string') return list(map(_convert, node.elts)) Matt McCredie -- http://mail.python.org/mailman/listinfo/python-list

Re: Traversing through variable-sized lists

2010-02-17 Thread Matt McCredie
> I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index /

Re: switch

2009-12-09 Thread Matt McCredie
hong zhang yahoo.com> writes: > > List, > > Python does not have switch statement. Any other option does similar work? > Thanks for help. > > --henry > > I see a couple of people have mentioned using a dictionary. If the value that you are switching on is a string, or could be made i

Re: import from a string

2009-11-03 Thread Matt McCredie
iu2 elbit.co.il> writes: > > Hi, > > Having a file called funcs.py, I would like to read it into a string, > and then import from that string. > That is instead of importing from the fie system, I wonder if it's > possible to eval the text in the string and treat it as a module. > > For exampl

Re: Read any function in runtime

2009-10-26 Thread Matt McCredie
Rhodri James wildebst.demon.co.uk> writes: > > On Fri, 23 Oct 2009 17:39:40 +0100, Matt McCredie gmail.com> > wrote: > > > joao abrantes gmail.com> writes: > > > >> > >> Hey. I want to make a program like this:print "Complete the fu

Re: Read any function in runtime

2009-10-23 Thread Matt McCredie
': statement = raw_input("Complete the function f(x)=") exec "f = lambda x:"+statement in {} print f(2) print f(4) print f(6) Matt McCredie -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows file paths, again

2009-10-22 Thread Matt McCredie
st fine to me. There is a difference between a python string literal written inside of a python script and a string read from a file. When reading from a file (or the registry) what you see is what you get. There is no need to do so much work. Matt McCredie -- http://mail.python.org/mailman/listinfo/python-list

Re: Insert image to a List box

2007-11-16 Thread Matt McCredie
> Thanks a lot for your patience. > I put the gif file to a folder called fig in my desktop. > dirpath = './fig' > still got error: > > Traceback (most recent call last): > File "11.py", line 238, in > img.config(image=gifsdict[imgname]) > NameError: name 'imgname' is not defined > You shou

Re: Insert image to a List box

2007-11-16 Thread Matt McCredie
On Nov 15, 2007 2:15 PM, linda. s <[EMAIL PROTECTED]> wrote: > > On 11/15/07, Matimus <[EMAIL PROTECTED]> wrote: > > On Nov 15, 12:45 pm, linda.s <[EMAIL PROTECTED]> wrote: > > > I run the following code and got the error (I put a .gif file on the > > > desktop) > > > Traceback (most recent call l

Re: Assertion for python scripts

2007-11-02 Thread Matt McCredie
On 11/2/07, matthias <[EMAIL PROTECTED]> wrote: > Howdy ! > > I started using the assert() stmt and found it quite useful :-) I > have only one problem: I don't > know how to turn them off again. > > I know that "-O" turns off assertions in general. However, how do I > pass thus parameter to > p

Re: Going past the float size limits?

2007-10-26 Thread Matt McCredie
> It would be great if I could make a number that can go beyond current > size limitations. Is there any sort of external library that can have > infinitely huge numbers? Way way way way beyond say 5x10^350 or > whatever it is? > > I'm hitting that "inf" boundary rather fast and I can't seem to wor

Re: __main__ : What is this?

2007-10-19 Thread Matt McCredie
> En Fri, 19 Oct 2007 21:26:22 -0300, Matimus <[EMAIL PROTECTED]> escribió: > > > The common pattern: > > > > if __name__ == "__main__": > > # do stuff > > > > IMHO better written: > > > > if "__main__" == __name__: > > # do stuff > > I'm intrigued why do you feel the second alternative is be

Re: Control Log File Size

2007-10-19 Thread Matt McCredie
> I've got an application running on linux which writes log files using the > python logging module. I'm looking for some help and advice to cap the size > which the file will grow too, something reasonably like 2Mb would be great. > > > > What is the best way to handle this kind of thing? Can this

Re: Newbi Q: What is a rational for strings not being lists in Python?

2007-10-15 Thread Matt McCredie
On 10/15/07, Dmitri O.Kondratiev <[EMAIL PROTECTED]> wrote: > To clarify my point: > reverse() is a lucky one - Python has variants of *this particular* > function both for lists and strings. Yet what about other list functions? > How in general, can I write a function that works both on list a

Re: Moving objects in Tkinter

2007-10-12 Thread Matt McCredie
On 10/12/07, Evjen Halverson <[EMAIL PROTECTED]> wrote: > I have tried to make a Tkinter program make a rectangle move down the > window, but did not succeed. All it does is make a rectangle trail. >What am I doing wrong? > > from Tkinter import* > root = Tk() > RectangleColor='orange' >

Re: I could use some help making this Python code run faster using only Python code.

2007-09-23 Thread Matt McCredie
> Yes, Digital Mars D is what I was referring to and yes I know D is not > as efficient as C++. If I knew of a good C++ compiler that is not > from Microsoft that works natively with Windows I would be happy to > consider using it. I've had good luck with MinGW (gcc compiled for windows). http:/

Re: I could use some help making this Python code run faster using only Python code.

2007-09-21 Thread Matt McCredie
> It would be nice if Python could be made to automatically detect the > LC and string translation patterns used by the unoptimized Python code > and make them into optimized Python code on the fly at runtime. I am > more than a little amazed nobody has chosen to build a JIT (Just In- > Time compi

Re: I could use some help making this Python code run faster using only Python code.

2007-09-21 Thread Matt McCredie
> Now I think I will code this little scrambler using nothing but the D > Language just to see whether there is any benefit in using D over > Python for this sort of problem. Isn't D compiled to machine code? I would expect it to win hands down. That is, unless it is horribly unoptimized. Matt --

Re: I could use some help making this Python code run faster using only Python code.

2007-09-20 Thread Matt McCredie
On 9/20/07, Python Maniac <[EMAIL PROTECTED]> wrote: > I am new to Python however I would like some feedback from those who > know more about Python than I do at this time. Well, you could save some time by not applying the scramble one line at a time (that is if you don't mind losing the line end

Re: re question

2007-09-20 Thread Matt McCredie
On 9/20/07, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Dan Bar Dov wrote: > > I'm trying to construct a regular expression to match valid IP address, > > without leading zeroes (i.e > > 1.2.3.4 , 254.10.0.0 , but not > > 324.1.1.1, nor 010.10.10.1

Re: re question

2007-09-20 Thread Matt McCredie
On 9/19/07, Dan Bar Dov <[EMAIL PROTECTED]> wrote: > I'm trying to construct a regular expression to match valid IP address, > without leading zeroes (i.e > 1.2.3.4, 254.10.0.0, but not 324.1.1.1, nor 010.10.10.1) > > This is what I come up with, and it does not work. > > r'(^[12]?\d{0,2}\.){3,3}[1

Re: Using python to create windows apps that everyone can use?

2007-09-18 Thread Matt McCredie
On 9/18/07, Thomas Harding <[EMAIL PROTECTED]> wrote: > Hi guys, sorry to post another topic on this, as I am aware that it has > already been posted a few times, but not with specifically what I am looking > for. I want an app that makes a gui interface for python (similar to > Microsoft visual st

Re: help - error when trying to call super class method

2007-09-09 Thread Matt McCredie
> I am trying to extend list class to build a stack class -- see code below--- > but I got an error when I try to call len method from list class here.. why? > Thanks in advance! Jeff did a good job of answering your questions. I just wanted to note that your pop is broken, but that doesn't matter

Re: Registering a python function in C

2007-09-04 Thread Matt McCredie
> > Is Maya a different python build than what is contained at python.org? > > If so, I suggest you get your C program to work with the latest python > > build > > from python.org. Then see if you can get it to work with the Maya > > version. > > Ok, did that. If I write a normal C++ program and u

Re: So what exactly is a complex number?

2007-08-31 Thread Matt McCredie
> So what exactly is a complex number? It is a math construct, and has almost nothing to do with Python, other than the fact that Python has a data type for them. So, here is a list of better ways to get information about complex numbers than asking python-list: 1. Google it: http://www.google.co

Re: an eval()-like exec()

2007-08-27 Thread Matt McCredie
> A python interactive interpreter works by having the user type in some > code, compiling and running that code, then printing the results. For > printing, the results are turned into strings. > > I would like make an interpreter which does this, without the last > part: i.e. where the results are

Re: Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Matt McCredie
> Image.open("C:\test.jpg") # this is what I have right now. And it can't > find the file or directory. The file is there (it is everywhere on my > computer now!!!) > > I found some code where they apply the file path to a variable in single > quotes. Is that how it is done. Also I thought single

Re: the del function

2007-08-27 Thread Matt McCredie
> For some odd reason the del array[ray] isn't actually deleting the array > item in the list I get the following output: > > C:\Documents and > Settings\program\Desktop\python\pygame>remix.py > [2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3] > [2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3] > [2, 2, 2, 2, 4, 4, 4, 3, 3, 3, 3

Re: Problem w/ Tkinter

2007-08-24 Thread Matt McCredie
On 8/24/07, Lamonte Harris <[EMAIL PROTECTED]> wrote: > How to fix my code, wth that doesn't help solve anything really.the Tkinter > tutorial doesn't even explain radio buttons correctly, let alone, everything > else. gah. can you give a answer that I can work from. You asked, "what can I do to f

Re: Problem w/ Tkinter

2007-08-24 Thread Matt McCredie
> text="Action?",command=self.V(a,b,c,d)).pack(anchor=W) doesn't even do > anything, what can I do to fix this problem? I see many mistakes. First: `command=self.V(a,b,c,d)' is actually calling self.V. You don't want to call self.V, which will assing `command' to the return value, you want to pas

Re: I can't get value of entry box, Tinker

2007-08-24 Thread Matt McCredie
> What/should I, can I do? Fix your code? > def login(): > global e2,e1 > print e2.get() > print e1.get() That should work. Matt -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python using a book based on version 1.5

2007-08-22 Thread Matt McCredie
> A friend of mine dropped off a copy of Sams Teach Yourself Python in > 24 Hours published in 2000. I skimmed the first couple of chapters > looking for the interpreter version and the book was based on version > Python version 1.5. > > Is this book still relevant? Should I toss it and look for

Re: What Are These Import/From Statements about?

2007-08-22 Thread Matt McCredie
> While that's an interesting link, I was thinking of the named items like: > Numeric, (this one I know about.) > Image > ImageChops > ImageTk > time > binascii > tkMessageBox > tkSimpleDialog The `image' ones are all part of PIL (Python Imaging Library) which is a third party module (http

Re: porting vc++ project to python?

2007-08-22 Thread Matt McCredie
> i have a very large project in visual studio2005->visual c++ in windowsxp. > i'd like to port it, or my next project, over to python. > is this possible without rewriting all my code? > are there multiple options to do this? > my project is so large, that entirely rewriting it > is actually no o

Re: how to convert a c program to java program

2007-08-17 Thread Matt McCredie
> I heard I need to port C program to JPython first and compile it to native > JAVA. I don't know > anything about JPython. Is there a tool to do the porting? If not, what is > the quickest way to learn > JPython? I'm assuming that you are refering to Jython. You probably want to start by learn

Re: threads, mutual exclusion, and lists

2007-08-16 Thread Matt McCredie
> Why do you think they are not? Because they aren't. You even mentioned that a few operations that aren't atomic. If operations are atomic it isn't necessarily because of the design of the list, but the design of CPython. More specifically the GIL. I don't mean to imply that you can't get a multi

Re: threads, mutual exclusion, and lists

2007-08-15 Thread Matt McCredie
> My question is -- are python list operations atomic? If they are not, > then I assume I need to put some mutual exclusion around the append() > and pop() calls ? They are not, but there is one included in the standard library: http://docs.python.org/dev/lib/module-Queue.html Matt -- http://mai

Re: try/finally exceptions dying

2007-08-14 Thread Matt McCredie
> I thought finally always propagated the > exception all the way up the stack until it was handled. Finally will propagate the exception up, unless another exception occurs within the finally block. Since there is not (yet: http://www.python.org/dev/peps/pep-3134/) exception chaining in Python, o

AttributeError: 'module' object has no attribute 'HTTPSHandler'

2007-08-13 Thread Matt McCredie
> > I am using Fedora Core 4 linux. Where should I look for _ssl.pyd ? I > am trying to build and use Python-2.5.1 > I don't have access to that type of system. I do know that you need OpenSSL to use ssl. It might be as simple as just finding and installing OpenSSL for fedora. You can also find t

Fwd: AttributeError: 'module' object has no attribute 'HTTPSHandler'

2007-08-10 Thread Matt McCredie
> I built and installed python 2.5 from source and when I do this: > > opener = urllib2.build_opener(SmartRedirectHandler(), > DefaultErrorHandler(), urllib2.HTTPSHandler()) > > I get this error. > AttributeError: 'module' object has no attribute 'HTTPSHandler' > > What should I do? You need `_ss

Re: pylint style convention

2007-07-23 Thread Matt McCredie
Which style convention is it referring to? Should these really be all caps? I think pylint is expecting that any variables declared outside of a function should be constants with special meanings (similar to #define or enum values in c). So, I guess to get rid of that message you should do som

Re: Images in Tkinter

2007-07-20 Thread Matt McCredie
That code doesn't tell me anything. You are going to have to post a more complete example to get help. Like, enough code so that I can run it and see the same problem. Also, I tried creating the image object outside class but it gives a runtime error saying it is too early to create an image obj

Re: Efficiently removing duplicate rows from a 2-dimensional Numeric array

2007-07-19 Thread Matt McCredie
Could you use a set of tuples? set([(1,2),(1,3),(1,2),(2,3)]) set([(1, 2), (1, 3), (2, 3)]) Matt On 7/19/07, Alex Mont <[EMAIL PROTECTED]> wrote: I have a 2-dimensional Numeric array with the shape (2,N) and I want to remove all duplicate rows from the array. For example if I start out wit

Re: class C: vs class C(object):

2007-07-19 Thread Matt McCredie
>How about "broke" instead of "deprecated": > > > >>> class Old: >... def __init__(self): >... self._value = 'broke' >... value = property(lambda self: self._value) >... How is this broken? Properties are not supported for old-style classes. They may not support features introduced in n

Re: How to check if an item exist in a nested list

2007-07-19 Thread Matt McCredie
Is there any way to check if an item in specific location in a multiple dimension nested exist? For example something like: if M_list[line][row][d] exist: do_something_0 else: do_something_1 Certainly: try: M_list[line][row][d] except IndexError: do_something_1 else: do_somethin

Re: Break up list into groups

2007-07-17 Thread Matt McCredie
That certainly is fast, unfortunately it doesn't pass all of the tests. I came up with those tests so I don't know how important they are to the original poster. I modified it and came up with a generator and a non-generator version based (roughly) on your algorithm, that are almost as quick, and