Re: Calling class method by name passed in variable
Sagari wrote: Greetings, Can someone suggest an efficient way of calling method whose name is passed in a variable? Given something like: class X: #... def a(self): # ... def b(self): # ... #... x = X() #... v = 'a' How do I call the method of x whose name is stored in v? Use getattr (stands for get attribute) to do this. fn = getattr(x, v) # Get the method named by v fn(...)# Call it Or in one line: getattr(x,v)(...) Gary Herron PHP code for this would be: class X { function a() { } } $x = new X(); $v = 'a'; $x->$v(); I need a solution for Python. Could you suggest anything? The task it to call a function whose name is taken from user-supplied input. Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
[Regexes] Stripping puctuation from a text
I want to strip punctuation from text. So I am trying, >>> p = re.compile('[a-zA-Z0-9]+') >>> p.sub('', 'I love tomatoes!! hell yeah! ... Why?') ' !! ! ... ?' Which gave me all the chars which I want to replace. So Next I tried by negating the regex, >>> p = re.compile('^[a-zA-Z0-9]+') >>> p.sub('', 'I love tomatoes!! hell yeah! ... Why?') ' love tomatoes!! hell yeah! ... Why?' But this removed the first char instead of the puctuation. So I guess ^ is matching start of line, instead of negation. How can I take negation of the regex here? -- http://mail.python.org/mailman/listinfo/python-list
can python do some kernel stuff?
Hi to all python now has grown to a versatile language that can accomplish tasks for many different purposes. However, AFAIK, little is known about its ability of kernel coding. So I am wondering if python can do some kernel coding that used to be the private garden of C/C++. For example, can python intercept the input of keyboard on a system level? someone told me it's a kernel thing, isn't it? -- http://mail.python.org/mailman/listinfo/python-list
Re: call f(a, *b) with f(*a, **b) ?
On May 22, 5:29 pm, "inhahe" <[EMAIL PROTECTED]> wrote: > "bukzor" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > This question seems easy but I can't figure it out. > > Lets say there's a function: > > > def f(a, *args): > > print a > > for b in args: print b > > > and elsewhere in your program you have a list and a dict like this: > > args = [2, 3] > > kwargs = {'a':1} > > > I'd like to get f() to print something like the following, but I can't > > figure out how. > > 1 > > 2 > > I think there's no 'standard' way to do this. but: > > import inspect > f(*map(kwargs.get, inspect.getargspec(f)[0])+args) > > i don't know if it works because i'm afraid to try it. if it doesn't the > solution is something similar to that. That does, in fact work. Thanks! I'm a little sad that there's no builtin way to do it, owell. >>> def f(a, *args): ... print a ... for b in args: print b ... >>> import inspect >>> a = [2,3] >>> b = {'a':1} >>> inspect.getargspec(f) (['a'], 'args', None, None) >>> map(b.get, inspect.getargspec(f)[0]) [1] >>> map(b.get, inspect.getargspec(f)[0]) + a [1, 2, 3] >>> f(*map(b.get, inspect.getargspec(f)[0]) + a) 1 2 3 -- http://mail.python.org/mailman/listinfo/python-list
Calling class method by name passed in variable
Greetings, Can someone suggest an efficient way of calling method whose name is passed in a variable? Given something like: class X: #... def a(self): # ... def b(self): # ... #... x = X() #... v = 'a' How do I call the method of x whose name is stored in v? PHP code for this would be: class X { function a() { } } $x = new X(); $v = 'a'; $x->$v(); I need a solution for Python. Could you suggest anything? The task it to call a function whose name is taken from user-supplied input. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: call f(a, *b) with f(*a, **b) ?
On May 22, 5:39 pm, "inhahe" <[EMAIL PROTECTED]> wrote: > >> 1 > >> 2 > > actually, you don't want it to print 3 also? if not, then you would do > f(*map(kwargs.get, inspect.getargspec(f)[0])+args[:1]) > > > import inspect > > f(*map(kwargs.get, inspect.getargspec(f)[0])+args) > > No, that was a typo. Thanks tho. -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes help
On 23 Mag, 07:48, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote: > > Yes, I know it but when I load a function (a=myDLL.myFUNCT()) I've an > > exception like this: > > > Traceback (most recent call last): > > File "", line 1, in > > myDLL.myFUNCT() > > File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__ > > func = self.__getitem__(name) > > File "C:\Python25\lib\ctypes\__init__.py", line 358, in __getitem__ > > func = self._FuncPtr((name_or_ordinal, self)) > > AttributeError: function 'myFUNCT' not found > > Then maybe the DLL doesn't contain a function called `myFUNCT`. Any > chance you compiled your C as C++ and name mangling kicked in? > > Can you show a minimal C source for a DLL, how you compiled it, what you > did on the Python side to call it, and how it fails? > > Ciao, > Marc 'BlackJack' Rintsch I've located my dll in c:\windows\system32 (in linux I aven't any problem) and I compiled it with dev-c++. The source code is C standard ANSII and is quite havy. If you like I can send it via mail (you can realy at [EMAIL PROTECTED]) . I've tryed to build a wrape with swig olso with same code and I can access at all the function. thanks Gianluca -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes help
On Thu, 22 May 2008 21:55:41 -0700, gianluca wrote: > Yes, I know it but when I load a function (a=myDLL.myFUNCT()) I've an > exception like this: > > Traceback (most recent call last): > File "", line 1, in > myDLL.myFUNCT() > File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__ > func = self.__getitem__(name) > File "C:\Python25\lib\ctypes\__init__.py", line 358, in __getitem__ > func = self._FuncPtr((name_or_ordinal, self)) > AttributeError: function 'myFUNCT' not found Then maybe the DLL doesn't contain a function called `myFUNCT`. Any chance you compiled your C as C++ and name mangling kicked in? Can you show a minimal C source for a DLL, how you compiled it, what you did on the Python side to call it, and how it fails? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC
George Maggessy wrote: Hi Gurus, I'm a Java developer and I'm trying to shift my mindset to start programming python. So, my first exercise is to build a website. However I'm always falling back into MVC pattern. I know it's a standard, but the implementation language affects the use of design patter. So, here goes my question. Is that OK if I follow this? Should I create DAOs, View Objects, Controllers and etc? Is there any sort of best practice / standard to Python? Cheers, George Look at Pylons. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is math.pi slightly wrong?
Dan Upton wrote: On Thu, May 22, 2008 at 2:53 PM, Mensanator <[EMAIL PROTECTED]> wrote: On May 22, 11:32 am, "Dutton, Sam" <[EMAIL PROTECTED]> wrote: I've noticed that the value of math.pi -- just entering it at the interactive prompt -- is returned as 3.1415926535897931, whereas (as every pi-obsessive knows) the value is 3.1415926535897932... (Note the 2 at the end.) Is this a precision issue, or from the underlying C, or something else? How is math.pi calculated? If you actually need that many digits, use a different library. import gmpy print gmpy.pi(64) # 64 bit precision 3.14159265358979323846 print gmpy.pi(128) # 128 bit precision 3.141592653589793238462643383279502884197 print gmpy.pi(16384) # 16384 bit precision 3.14159265358979323846264338327950288419716939937510582097494459 ... Who wants to verify that that's correct to that many digits? ;) Ramanujan? http://numbers.computation.free.fr/Constants/Pi/piramanujan.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Relationship between GUI and logic?
On Thu, 22 May 2008 23:37:45 -0400, John Salerno wrote: > I know that it is good programming practice to keep GUI and logic code > physically separate, by using XRC for example, but I'm wondering if it's > also good practice (and even possible) to keep them separate from an > implementation standpoint as well. Basically what I mean is, should it > be possible to write, for example, the logic for a strategy game without > even knowing what the graphics will look like or how they will work? Yes, that's possible. > To be more specific, let's say I want to create a simple, 2D strategy > game. It will have a board layout like chess or checkers and the player > will move around the board. Let's say this is all I know, and perhaps I > don't even know *this* for sure either. Is it possible to write the > logic for such a game at this point? Maybe even this is possible. But here you are not only drawing the line between GUI and logic but also within the logic part itself because the board layout isn't (just) a GUI issue. If you have checkers, hexagons, or other shapes also has influence on the logic part, because you need slightly different algorithms for finding ways from tile `A` to tile `B`, or to decide when a piece is blocked by others, and how the rules to move pieces around look like. Just imagine how to modify chess rules to a board with hexagonal patterns. It would severely change the logic part. > Another example could be printing messages to the player. If I need to > say "You killed the monster!", is there a general way to write this, or > do I need to specifically refer to GUI widgets and methods, etc. in > order for it to be displayed properly? The observer pattern can be used here. The GUI has to register a callback function with your logic engine and every time you want to inform the player about something, your game logic calls that function with the message. It doesn't have to know if it will be rendered as graphic on screen, displayed as text in a terminal, or synthesized as sexy female computer voice. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorator metaclass
Le Friday 23 May 2008 04:28:22 [EMAIL PROTECTED], vous avez écrit : > Hi, > I would like to create a Decorator metaclass, which automatically > turns a class which inherits from the "Decorator" type into a > decorator. > A decorator in this case, is simply a class which has all of its > decorator implementation inside a decorator() method. Every other > attribute access is being proxied to decorator().getParent(). > > ... > > --- > Unfortunately this does not work. The newly defined __init__ method > inside __new__, does a call to impl(*args, **dargs). However, since > the HBar.__init__ calls the Decorator.__init__ method, but the > HBar.__init__ method no longer resides inside HBar, but rather inside > HBarImpl (which is no longer a subtype of Decorator), the compiler > complains that Decorator.__init__ is not being called with a Decorator > instance as its first argument (which is true). > I tried changing the definition of impl inside __new__ to have > Decorator as one of its bases, but then for some reason impl(*args, > **dargs) asks for 4 arguments (just like __new__) and I have no clue > as to why that happens. > > Any help on this? > The problem with kind of design is that you must break the rules of class inheritance, and it seems like a strange idea to implement decorators by inheritance. Of course you could do all sort of magic with python, but what is your goal ? In your example, should the implementation types inherit from each other ? In that case, do you want to preserve the same semantic for __init__ as in standard python class (this could be a hard job) ? This quick fix seems to work with your example, but add extra magic to automatically call the super __init__ of the parent implementation, this could be a bad idea, use with caution ! (I still think it's a bad design, using composition and proxy classes is much more simple and clear) class DecoratorType(type): def __new__(cls, name, bases, dct): # create a new class which will store all of the implementation parent_impl_type = bases[0] is object and object \ or bases[0]._impl_type impl = type('%sImpl'%name,(parent_impl_type,),dict(dct)) dectype = type.__new__(cls, name, bases, {'_impl_type' : impl }) # update the old class to implement this implementation def __init__(self, *args, **dargs): print args, dargs new_impl = impl(*args, **dargs) super(dectype._impl_type, new_impl).__init__(*args, **dargs) object.__setattr__(self, '_impl', new_impl) def decorator(self): return object.__getattribute__(self,'_impl') def __getattribute__(self, attr): if attr=="decorator": return object.__getattribute__(self,'decorator') return getattr(object.__getattribute__( self, 'decorator')(), attr) dectype.__init__ = __init__ dectype.decorator = decorator dectype.__getattribute__ = __getattribute__ return dectype class Decorator(object): __metaclass__ = DecoratorType class HBar(Decorator): def __init__(self, number): print 'hb:', number self._number = number def inc(self): self._number += 1 def p(self): print self._number class HBar2(HBar) : def __init__(self, number): print 'hb2:', number self._hb2 = number def inc2(self): self._hb2 += 1 def p2(self): print self._hb2 hbar = HBar(10) for each in dir(hbar.decorator()): print each hbar.decorator().p() hbar.decorator().inc() hbar.decorator().p() hb2 = HBar2(5) hb2.p() hb2.p2() hb2.inc() hb2.p() hb2.p2() hb2.inc2() hb2.p() hb2.p2() -- _ Maric Michaud _ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is math.pi slightly wrong?
Mensanator wrote: On May 22, 11:32 am, "Dutton, Sam" <[EMAIL PROTECTED]> wrote: I've noticed that the value of math.pi -- just entering it at the interactive prompt -- is returned as 3.1415926535897931, whereas (as every pi-obsessive knows) the value is 3.1415926535897932... (Note the 2 at the end.) Is this a precision issue, or from the underlying C, or something else? How is math.pi calculated? If you actually need that many digits, use a different library. import gmpy print gmpy.pi(64) # 64 bit precision 3.14159265358979323846 print gmpy.pi(128) # 128 bit precision 3.141592653589793238462643383279502884197 print gmpy.pi(16384) # 16384 bit precision 3.14159265358979323846264338327950288419716939937510582097494459 23 Heh! I wonder who needs that many digits? Certainly not number theorists (they need a LOT more). Certainly not physicists -- they need about 30 digits to be within 1% of any measurement from molecules to galaxies. Certainly not engineers, they need half the digits that physicists need. Cryptographers are making a dire mistake if they are using PI in any computations (possible exception for elliptic curves -- see number theorists, above) ... so -- other than PI-philes, who needs PI to thousands of digits? -- http://mail.python.org/mailman/listinfo/python-list
Re: serach file for regexp, return if found?
[EMAIL PROTECTED] wrote: > i want to search a document for a particular regexp and then store > that regexp to a file. > but search and match only returns matchobjects(what are those anyway? > i dont get what to do with them, do they contain true/false, > stringposition etc?) > how do i do: > for rows in file: > print regexp.find ## or something equiavlent Is this what you are trying to do: for row in file('/etc/services'): if re.match('^ssh', row): print row Yves. http://www.SollerS.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
cm_gui wrote: Python is slow.Almost all of the web applications written in Python are slow. Zope/Plone is slow, sloow, so very slooow. Even Google Apps is not faster. Neither is Youtube. Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster than Python. Okay, they probably use caching or some code compilation -- but Google Apps and those Zope sites probably also use caching. I've yet to see a web application written in Python which is really fast. So --- don't use Google * shrug * Personally I find PHP to be a hideous language -- it has only one use. It is Perl for people who can be bothered to learn a general purpose programming language and just write web applications. Python is a general purpose programming language ... it does web nicely (Django and pylons!), it supports real OOP and OOD, it's extensible, it has a smart set of libraries, intelligent and coherent interfaces, it sails across platforms, it has at least one great ORM (SQLAlchemy) and I keep discovering new cool things about the language as a recent convert that make me wonder why I would ever write another large application in Perl or Java. I find Zope to be a mess and it gives me a headache ... but it Zope is an *application framework*, not a *programming language*. So, I think you are barking up the wrong straw man (if I may mix metaphors). But that's just my $0.02. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
Peter Otten <[EMAIL PROTECTED]> wrote: > > A slightly similar problem: If I want to "merge," say, list1=[1,2,3] with > > list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way with "zip" > > to do so? > >>> items = [None] * 6 > >>> items[::2] = 1,2,3 > >>> items[1::2] = 4,5,6 > >>> items > [1, 4, 2, 5, 3, 6] My problem with this solution is that you depend on knowing how many elements you have in each list ahead of time. Assuming that both list are of the same length, then, I find the following more elegant: list1=[1,2,3] list2=[4,5,6] reduce(lambda x, y: x+y, zip(list1, list2)) of course, zip creates tuples, so you end up with a tuple, therefore if you need for your solution to be a list: list(reduce(lambda x, y: x+y, zip(list1, list2))) of reduce(lambda x, y: x+y, list(zip(list1, list2)) ) Yves. http://www.SollerS.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On 23 Mai, 00:51, Larry Bates <[EMAIL PROTECTED]> wrote: > > I've yet to see a web application written in Python which is really > > fast. > > You are just dead wrong about this. No, he can demand whatever he wants and we can be stupid enough to respond. -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes help
On 23 Mag, 01:14, Larry Bates <[EMAIL PROTECTED]> wrote: > gianluca wrote: > > Hy, > > I need help about use dll with ctypes. I've compiled my dll C library > > and I copied it in c:\windows\system32. When I load it with > > "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem all OK but > > python don't see the dll function. with dir(myDLL) I've only this: > > ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', > > '__getattr__', '__getattribute__', '__getitem__', '__hash__', > > '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', > > '__repr__', '__setattr__', '__str__', '__weakref__', '_handle', > > '_name'] > > > Could anybody help me > > > Thanks > > > Gianluca > > Since it isn't python, dir can'd do much introspection on the object to > produce > the type of output you desire. You have to know the functions (methods) that > you want to call in your dll and call them. > > -Larry Bates Yes, I know it but when I load a function (a=myDLL.myFUNCT()) I've an exception like this: Traceback (most recent call last): File "", line 1, in myDLL.myFUNCT() File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__ func = self.__getitem__(name) File "C:\Python25\lib\ctypes\__init__.py", line 358, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'myFUNCT' not found Thanks for help -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
On 13 Mai, 01:39, Dave Parker <[EMAIL PROTECTED]> wrote: > I've read that one of the design goals of Python was to create an easy- > to-use English-like language. That's also one of the design goals of > Flaming Thunder athttp://www.flamingthunder.com/ , which has proven > easy enough for even elementary school students, even though it is > designed for scientists, mathematicians and engineers. "Why on earth shall kids program and even more serious: why shall I program in a language for kids?" -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
I used python to generate php code. But that was before I knew what vast troves of python web frameworks there were. :) On Thu, May 22, 2008 at 11:40 PM, inhahe <[EMAIL PROTECTED]> wrote: > > > PHP can do that. There are also a number of templating engines > > available. The nice thing about PHP is you have a choice. > > i just meant that php is sort of invented to combine html and code, so if > you use python instead you should use a templating engine. but i suppose > it's useful for php too. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- | _ | * | _ | | _ | _ | * | | * | * | * | -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
> PHP can do that. There are also a number of templating engines > available. The nice thing about PHP is you have a choice. i just meant that php is sort of invented to combine html and code, so if you use python instead you should use a templating engine. but i suppose it's useful for php too. -- http://mail.python.org/mailman/listinfo/python-list
RE: How do I make a copy of my class object?
Nevermind. I ended up making a copy of everything within the class since I'm storing bitmaps anyway. It works. I'll read up more on the deepcopy() function. > To: python-list@python.org> From: [EMAIL PROTECTED]> Subject: Re: How do I > make a copy of my class object?> Date: Thu, 22 May 2008 17:52:02 -0400> > > "Marlin Rowley" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL > PROTECTED]> > I have a class object which has the usual data members and > functions.> > I'm trying to make a copy of this class (which includes > wx.Bitmap objects)> > but deepcopy() doesn't seem to work. How would I do > this?> > Are you trying to make a copy of the "class object" or of a class > instance?> > What error message are you getting when you call deepcopy() on > this object?> > > > > --> http://mail.python.org/mailman/listinfo/python-list _ Keep your kids safer online with Windows Live Family Safety. http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL_Refresh_family_safety_052008-- http://mail.python.org/mailman/listinfo/python-list
Re: Relationship between GUI and logic?
On May 23, 1:37 pm, John Salerno <[EMAIL PROTECTED]> wrote: > Basically, the question is this: can you write the logic behind a > program (whether it be a game, an email client, a text editor, etc.) > without having any idea of how you will implement the GUI? Hey John, Are you familiar with the Model-View-Controller pattern? It specifically addresses this issue, and is very common in game development. In your example of a grid-based game like chess, the board & the pieces would all be defined in the Model. The board may be a 2D array, so to move a piece, the piece only has to know how to address locations within the array, or even better, only has to know how to tell the board where it's moving to, so the pieces don't have to know how the board is implemented. The View interprets & displays the Model. You could represent each square by a bitmap, draw a 3d object, or use ASCII etc etc. The Controller maps user input to Model behaviour, so pressing 'up' while a piece is highlighted may call something like piece.move_north(), which updates the necessary entities in the Model to reflect the move. It generally also passes information from the Model to the View, although it's not uncommon for the View to just refer to the Model separately. So you can think of the Model as a simulation of the behaviour you want, while the View is _a_ representation of that simulation. The simulation doesn't care if you're displaying it in 2D or 3D, it cares about pieces and board positions. By separating the Model & the View, you also allow for multiple representations of the same data, such as having a 2D overhead map and a 3D visualisation of the same information. - alex23 -- http://mail.python.org/mailman/listinfo/python-list
Re: Relationship between GUI and logic?
John Salerno wrote: Basically, the question is this: can you write the logic behind a program (whether it be a game, an email client, a text editor, etc.) without having any idea of how you will implement the GUI? Chess already has at least two solutions that are in widespread use: Winboard UCI (Universal Chess Interface) Basically you write your chess "engine" to speak either Winboard or UCI and then you can "run" it in one of the various GUI interfaces, (such as Shredder, Fritz, Arena, ...). See: http://www.playwitharena.com/ or the comparatively young: http://pychess.googlepages.com/(which is written in Python) Patrick -- http://mail.python.org/mailman/listinfo/python-list
Relationship between GUI and logic?
I know that it is good programming practice to keep GUI and logic code physically separate, by using XRC for example, but I'm wondering if it's also good practice (and even possible) to keep them separate from an implementation standpoint as well. Basically what I mean is, should it be possible to write, for example, the logic for a strategy game without even knowing what the graphics will look like or how they will work? To be more specific, let's say I want to create a simple, 2D strategy game. It will have a board layout like chess or checkers and the player will move around the board. Let's say this is all I know, and perhaps I don't even know *this* for sure either. Is it possible to write the logic for such a game at this point? Let's say I want to write a "move" function (or perhaps it would be a method of a "Character" class) for moving the player around. Could you really write this function without 1) knowing what the interface will look like, and 2) integrating GUI code with the logic? Another example could be printing messages to the player. If I need to say "You killed the monster!", is there a general way to write this, or do I need to specifically refer to GUI widgets and methods, etc. in order for it to be displayed properly? Basically, the question is this: can you write the logic behind a program (whether it be a game, an email client, a text editor, etc.) without having any idea of how you will implement the GUI? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC
In fact, the Pylons web framework is geared toward the MVC approach. http://pylonshq.com/ On Thu, May 22, 2008 at 7:48 PM, George Maggessy <[EMAIL PROTECTED]> wrote: > Hi Gurus, > > I'm a Java developer and I'm trying to shift my mindset to start > programming python. So, my first exercise is to build a website. > However I'm always falling back into MVC pattern. I know it's a > standard, but the implementation language affects the use of design > patter. So, here goes my question. Is that OK if I follow this? Should > I create DAOs, View Objects, Controllers and etc? Is there any sort of > best practice / standard to Python? > > Cheers, > George > -- > http://mail.python.org/mailman/listinfo/python-list > -- | _ | * | _ | | _ | _ | * | | * | * | * | -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
inhahe wrote: I don't like php. I tried it once and I had it sort a list, but the list was apparently too long for its sorting function because it just sorted the first so-many elements of it and left the rest in order, and didn't generate any error. I like a language that's actually determined by what you tell it to do. Then I suspect you had an error in your code. PHP's sort functions work fine. I hear it has a lot of security issues too. The language has no security issues. Programmers have security issues - whether it be PHP, Python or any other language. I'm not sure that php *runs* faster than python, having seen benchmarks, but it certainly loads faster. Maybe not so much of a difference once python25.dll is already in the cache though (speaking from a windows perspective). because when i load a program it can take a while but it's pretty quick if i'd just loaded one recently. but you don't necessarily have to load python for each page rendering anyway. I like the Python language a lot better than php. but I just really like Python. I like PHP much better than Python. To each their own. php mixes html and code out-of-the-box (sort of.. i guess it's more like a reversal of which one is explicit)... if you use Python you should look into a 'templating engine' like mako. i use cheetah, but mako is supposed to be better. PHP can do that. There are also a number of templating engines available. The nice thing about PHP is you have a choice. i think Python is the easiest language to learn, with the possible exception of qbasic (just because making multidimensional arrays in python isnt that obvious, although maybe it is using numpy, i've never tried it). Python isn't as easy as basic if you use/have to read the more advanced features, but those aren't even available in basic. so I find it a comfortable learning curve. I found PHP easier to learn than Python. But that may be because I already have a strong C/C++ background. There isn't anything wrong with Python. I just prefer PHP. -- == Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. [EMAIL PROTECTED] == -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
On Thu, 22 May 2008 19:35:50 -0700, Charles Hixson wrote: > Although when comparing Candygram with Erlang it's worth noting that > Candygram is bound to one processor, where Erlang can operate on > multiple processors. (I'd been planning on using Candygram for a project > at one point, but this made it unusable.) Really? The FAQ says it uses operating system threads, which I would have thought would mean it runs on multiple processors (modulo, I suppose, the issues with the GIL). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
On Thursday 22 May 2008 13:30:07 Nick Craig-Wood wrote: > ... > >From Armstrong's book: The expression Pattern = Expression causes > > Expression to be evaluated and the result matched against Pattern. The > match either succeeds or fails. If the match succeeds any variables > occurring in Pattern become bound. > > It is a very powerful idea and one which (along with the concurrency > and message passing from Erlang) has been implemented for python :- > > http://candygram.sourceforge.net/ > > I've been reading the Erlang book and I have to say it has given me a > lot of insight into python... Although when comparing Candygram with Erlang it's worth noting that Candygram is bound to one processor, where Erlang can operate on multiple processors. (I'd been planning on using Candygram for a project at one point, but this made it unusable.) -- http://mail.python.org/mailman/listinfo/python-list
Decorator metaclass
Hi, I would like to create a Decorator metaclass, which automatically turns a class which inherits from the "Decorator" type into a decorator. A decorator in this case, is simply a class which has all of its decorator implementation inside a decorator() method. Every other attribute access is being proxied to decorator().getParent(). Here's my attempt: --- from new import classobj class DecoratorType(type): def __new__(cls, name, bases, dct): dct2 = {} for key, val in dct.iteritems(): dct2[key] = val # create a new class which will store all of the implementation impl = classobj('%sImpl'%name,(),dct2) # update the old class to implement this implementation def __init__(self, *args, **dargs): object.__setattr__(self, '__impl', impl(*args, **dargs)) def decorator(self): return object.__getattribute__(self,'__impl') def __getattribute__(self, attr): if attr=="decorator": return object.__getattribute__(self,'decorator') return getattr(object.__getattribute__(self, 'decorator') ().getParent(), attr) dct = {} dct['__init__'] = __init__ dct['decorator'] = decorator dct['__getattribute__'] = __getattribute__ return type.__new__(cls, name, bases, dct) class Decorator(object): __metaclass__ = DecoratorType class HBar(Decorator): def __init__(self, number): Decorator.__init__(self) self._number = number def inc(self): self._number += 1 def p(self): print self._number hbar = HBar(10) for each in dir(hbar.decorator()): print each hbar.decorator().p() hbar.decorator().inc() hbar.decorator().p() --- Unfortunately this does not work. The newly defined __init__ method inside __new__, does a call to impl(*args, **dargs). However, since the HBar.__init__ calls the Decorator.__init__ method, but the HBar.__init__ method no longer resides inside HBar, but rather inside HBarImpl (which is no longer a subtype of Decorator), the compiler complains that Decorator.__init__ is not being called with a Decorator instance as its first argument (which is true). I tried changing the definition of impl inside __new__ to have Decorator as one of its bases, but then for some reason impl(*args, **dargs) asks for 4 arguments (just like __new__) and I have no clue as to why that happens. Any help on this? Regards, Thomas K. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
Larry Bates wrote: If your Python program is slow, you have almost assuredly approached it with a wrong method or algorithm. I agree for most applications. There are however times where Python just isn't fast enough, and that's usually when people write extension modules. I have yet to see a chess engine written in Python that is competitive with even a below average C or C++ chess engine. The same could be said of Java, VB, C#, Pearl, ... So there ARE some tasks that Python just isn't suited for due to performance, but not enough for it to steer anyone away from Python. I have been working on a chess engine and have found that I prototype in Python and then port to the D programming language, (which IS fast). For example, one of my routines, (generating pseudo-legal moves -- no evaluation), in Python runs at 700,000 moves per second, (using Psyco). Ported to D it runs at 22 million moves per second. Python's advantage is in the software development and maintenance phases. As long as the runtime phase is fast ENOUGH, Python kicks most other languages butts. Patrick -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC
George Maggessy wrote: Hi Gurus, I'm a Java developer and I'm trying to shift my mindset to start programming python. So, my first exercise is to build a website. However I'm always falling back into MVC pattern. I know it's a standard, but the implementation language affects the use of design patter. So, here goes my question. Is that OK if I follow this? ... Yes. Python does not impose design patterens onto developers. Pick your poison. It is somewhat OOP, but allows for other development paradigms as well... rather like C++ IMO although a bit more OOP focused. Best of luck, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC
In my experience, python is very pattern agnostic. You can do functional or object oriented or procedural fairly easily, have deep or light object trees, or even mix procedural style with some object oriented code if you like. "There should be one way to do it" tends to not apply as much as some would say, although the language doesn't bend over backward to make sure programmers have flexibility. MVC is a well respected pattern, and most of the major python web frameworks are designed in an MVC way, so you should be just fine to use MVC for your application. Worry more about what pattern fits your application, than whether your pattern fits the language. For myself, whenever I try to do strict MVC, it always tends to blend together. I usually get some sort of MC+V or MV+C sort of hybrid. The model is also the view, or the controller is also the model. But that's just how I think. Just keep in mind that python is not java, and you should be able to transition very easily. In fact, you could pretend python is java and go far, but you risk irritating other python programmers who look at your code :) We had to use jython for a class, and my friend's code (he's a java programmer) made me want to pull out my hair. Private variables and get/set functions all over the place... -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning to 'try' block after catching an exception
On May 23, 4:01 am, "inhahe" <[EMAIL PROTECTED]> wrote: > Might have a stack overflow issue, if it retries too many times? In which example? Neither of them is looping... -- http://mail.python.org/mailman/listinfo/python-list
Re: serach file for regexp, return if found?
On May 23, 9:10 am, [EMAIL PROTECTED] wrote: > but search and match only returns matchobjects(what are those anyway? > i dont get what to do with them, do they contain true/false, > stringposition etc?) It's all covered in the docs: http://docs.python.org/lib/module-re.html http://docs.python.org/lib/match-objects.html -- http://mail.python.org/mailman/listinfo/python-list
MVC
Hi Gurus, I'm a Java developer and I'm trying to shift my mindset to start programming python. So, my first exercise is to build a website. However I'm always falling back into MVC pattern. I know it's a standard, but the implementation language affects the use of design patter. So, here goes my question. Is that OK if I follow this? Should I create DAOs, View Objects, Controllers and etc? Is there any sort of best practice / standard to Python? Cheers, George -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On May 23, 2:14 am, cm_gui <[EMAIL PROTECTED]> wrote: > I've yet to see a web application written in Python which is really > fast. Then stop looking at your own inept Python code and open your eyes. -- http://mail.python.org/mailman/listinfo/python-list
Re: call f(a, *b) with f(*a, **b) ?
>> 1 >> 2 actually, you don't want it to print 3 also? if not, then you would do f(*map(kwargs.get, inspect.getargspec(f)[0])+args[:1]) > import inspect > f(*map(kwargs.get, inspect.getargspec(f)[0])+args) > -- http://mail.python.org/mailman/listinfo/python-list
Re: spider, why isnt it finding the url?
On 23 Maj, 02:02, [EMAIL PROTECTED] wrote: > this program doesnt produce any output, however i know from testing > that the url-regexp matches urls... > > import urllib > import re > > site = urllib.urlopen("http://www.python.org";) > > email = re.compile(r'[EMAIL PROTECTED],4}') > url = re.compile("^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1} > ([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})? > ((\?\w+=\w+)?(&\w+=\w+)*)?") > > for row in site: > obj = url.search(row) > if obj != None: > print obj.group() hmm ok it it printing it rows per rows. not what i expected. -- http://mail.python.org/mailman/listinfo/python-list
Re: call f(a, *b) with f(*a, **b) ?
"bukzor" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This question seems easy but I can't figure it out. > Lets say there's a function: > > def f(a, *args): >print a >for b in args: print b > > and elsewhere in your program you have a list and a dict like this: > args = [2, 3] > kwargs = {'a':1} > > I'd like to get f() to print something like the following, but I can't > figure out how. > 1 > 2 I think there's no 'standard' way to do this. but: import inspect f(*map(kwargs.get, inspect.getargspec(f)[0])+args) i don't know if it works because i'm afraid to try it. if it doesn't the solution is something similar to that. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTMLParser error
On May 23, 5:06 am, [EMAIL PROTECTED] wrote: > Nope, this is my first experience with object oriented programming, > only been learning python for a few weeks but it seemed simple enough > to inspire me to be a bit ambitious. If you could hook me up with some > good docs that would be great. I was about to but a book on python, > specifically OO based, but il look at these docs first. I understand > most of the concepts of inheritance, just not ever used them before. Ah, okay, I'm really sorry, if I'd known I would've tried to explain things a little differently :) Mark Pilgrim's Dive Into Python is a really good place to start: http://www.diveintopython.org/toc/index.html For a quick overview of object oriented programming in Python, try: http://www.freenetpages.co.uk/hp/alan.gauld/ Specifically: http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm But don't hesitate to ask questions here or even contact me privately if you'd prefer. -- http://mail.python.org/mailman/listinfo/python-list
Re: statically linking release build on mac
Here is the error: code 4, error number 0 (Symbol not found: _Py_DebugFlag Referenced from: /Library/Application Support/Digidesign/Plug-Ins/Play.dpm/Contents/MacOS/Play Expected in: /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit ) On Thu, May 22, 2008 at 10:13 AM, Patrick Stinson < [EMAIL PROTECTED]> wrote: > I get an error reporting an unfound symbol using a statically linked > release build of python2.5 on a OSX-Tiger. This works fine on leopard, where > the system default python is version 2.5.1 - the same version that I'm using > to link to. > > Sorry, I'm currently screwing with my configs and don't have a build to run > (my bad :) anymore, but the error is basically this: > > Undefined symbol: _PY_DebugFlag > Referenced From: > Expected in: > > I moved the system python frameworks out of the frameworks path for the > build and run just to make sure that they weren't somehow getting in the > way. I found that that symbol is defined in pydebug.h for both release and > debug builds. Also, I discovered that I can fix the problem with some of my > targets (I have both standalone exe and plugin lib versions of my app code) > by referencing the variable directly like this: int mine = Py_DebugFlag, > which fixes that symbol but then the next symbol in pydebug (PY_VerboseFlag) > is reported as undefined. After some playing with it, I found that the > following code will fix the problem in a basic standalone app: > > int _mine; > void *__p = NULL; > _mine = Py_DebugFlag; > _mine = Py_VerboseFlag; > _mine = Py_InteractiveFlag; > _mine = Py_OptimizeFlag; > _mine = Py_NoSiteFlag; > _mine = Py_UseClassExceptionsFlag; > _mine = Py_FrozenFlag; > _mine = Py_TabcheckFlag; > _mine = Py_UnicodeFlag; > _mine = Py_IgnoreEnvironmentFlag; > _mine = Py_DivisionWarningFlag; > _mine = _Py_QnewFlag; > __p = (void *) _PyOS_ReadlineTState; > __p = (void *) PyOS_ReadlineFunctionPointer; > > > Woah, don't I feel like the lib is jerking me around a little? Anyway, this > works if I put it in main() for a standalone target, in a semi-random class > constructor for the AudioUnit target, and I still can't find the right place > to put it for the RTAS ( > http://www.digidesign.com/index.cfm?query=developers%20plugin_info%20rtas.cfm&langid=1) > target. It's a little weird that I'm getting this at runtime and not at > link-time since I'm linking statically. > > This is the standalone main() that works, but fails if I remove the above > code: > > #include > > int main(int, char **) > { > int mine = -1; > void *p = NULL; > > mine = Py_DebugFlag; > mine = Py_VerboseFlag; > mine = Py_InteractiveFlag; > mine = Py_OptimizeFlag; > mine = Py_NoSiteFlag; > mine = Py_UseClassExceptionsFlag; > mine = Py_FrozenFlag; > mine = Py_TabcheckFlag; > mine = Py_UnicodeFlag; > mine = Py_IgnoreEnvironmentFlag; > mine = Py_DivisionWarningFlag; > mine = _Py_QnewFlag; > p = (void *) _PyOS_ReadlineTState; > p = (void *) PyOS_ReadlineFunctionPointer; > > Py_Initialize(); > > Py_Finalize(); > } > > > It seems to me like this might have something to do with setting up a > symbol lookup table correctly or something, I don't know. I'm not having any > problems with debug builds. This is the relevant part of my config.status. > > ac_cs_version="\ > > python config.status > 2.5 > > configured by ./configure, generated by GNU Autoconf > 2.59, > > with options \"'--enable-universalsdk' '--disable-shared'\" > > > Help? *whimper*.. Cheers. > > -- http://mail.python.org/mailman/listinfo/python-list
spider, why isnt it finding the url?
this program doesnt produce any output, however i know from testing that the url-regexp matches urls... import urllib import re site = urllib.urlopen("http://www.python.org";) email = re.compile(r'[EMAIL PROTECTED],4}') url = re.compile("^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1} ([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})? ((\?\w+=\w+)?(&\w+=\w+)*)?") for row in site: obj = url.search(row) if obj != None: print obj.group() -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __getitem__
> Apparently, args already is a tuple, so this should be: > > def __getitem__(self, args): > > Is this documented somewhere? I couldn't find it anywhere. > Don't know, I just assumed it would take multiple arguments because I knew I had seen the form d[1,2] before, which incidentally is equivalent to d[(1,2)] so I guess it makes sense that args is a tuple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On May 22, 1:18 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > My mum's fast... > Arnaud Was it a good idea to include that bit in a troll response? If English isn't your first language, it's one of those language idioms that's not very nice to say about someone's mother (especially your own mother). Erich -- http://mail.python.org/mailman/listinfo/python-list
Tun/Tap Driver using OpenVPN and DeviceIoControl
Hello I am trying to port some code and I am running into some issues I may or may not be able to solve on my own and would appreciate your help Basically I am trying to open the Tun Driver through openvpn in Ether (Tap mode). code is as follows f = win32file.CreateFile("C:\\WINDOWS\\System32\\drivers\\tunmp.sys", GENERIC_READ, 0, None, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) if WINDOWS: ifs = win32file.DeviceIoControl(f, TUNSETIFF, struct.pack("16sH", "wj%d", TUNMODE), 0, None) else: ifs = ioctl(f, TUNSETIFF, struct.pack("16sH", "wj%d", TUNMODE)) ifname = ifs[:16].strip("\x00") print "Interface %s created. Configure it and use it" % ifname but does not seem to work so well I get "The Paramater is incorrect" Traceback (most recent call last): File "wifi.py", line 167, in ifs = win32file.DeviceIoControl(f, TUNSETIFF, struct.pack("16sH", "wj%d", TU NMODE), 0, None) pywintypes.error: (87, 'DeviceIoControl', 'The parameter is incorrect.') Would appreciate any help Ty -- http://mail.python.org/mailman/listinfo/python-list
Re: simple way to touch a file if it does not exist
On May 22, 12:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Wed, 21 May 2008 17:56:38 -0700, bukzor wrote: > > On May 21, 5:37 pm, Nikhil <[EMAIL PROTECTED]> wrote: > > >> if os.path.exists('file'): > >> open('file', 'w').close() > > >> Right? > > > You only want to blank it if it exists? If it doesn't exist you won't > > create it. > > The .close() is superlative: since you don't keep the value, it gets > > deallocated and closed by the destructor. > > The language neither guarantees *when* an object will be deallocated nor > that its destructor is called *at all*. It's cleaner to explicitly close > the file. > > Ciao, > Marc 'BlackJack' Rintsch Good to know. -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __getitem__
[EMAIL PROTECTED] wrote: > actually i ddin't think about the fact that you're overloading dict, which > can already take multiple values in getitem Oh, I didn't know that. I totally misinterpreted the error message. > so how about > > class crazy: pass > > and then in your dict class: > > def __getitem__(*args): Apparently, args already is a tuple, so this should be: def __getitem__(self, args): Is this documented somewhere? I couldn't find it anywhere. Thanks. Ciao Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On May 22, 12:14 pm, cm_gui <[EMAIL PROTECTED]> wrote: > Python is slow.Almost all of the web applications written in > Python are slow. Zope/Plone is slow, sloow, so very slooow. Even > Google Apps is not faster. Neither is Youtube. > Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster > than Python. > Okay, they probably use caching or some code compilation -- but Google > Apps and those Zope sites probably also use caching. > > I've yet to see a web application written in Python which is really > fast. I expect Dave Parker here any minute to tell us how Flaming Thunder isn't slow. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
call f(a, *b) with f(*a, **b) ?
This question seems easy but I can't figure it out. Lets say there's a function: def f(a, *args): print a for b in args: print b and elsewhere in your program you have a list and a dict like this: args = [2, 3] kwargs = {'a':1} I'd like to get f() to print something like the following, but I can't figure out how. 1 2 -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes help
gianluca wrote: Hy, I need help about use dll with ctypes. I've compiled my dll C library and I copied it in c:\windows\system32. When I load it with "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem all OK but python don't see the dll function. with dir(myDLL) I've only this: ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_handle', '_name'] Could anybody help me Thanks Gianluca Since it isn't python, dir can'd do much introspection on the object to produce the type of output you desire. You have to know the functions (methods) that you want to call in your dll and call them. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Using os.walk to return files in subdirectories
dj wrote: Hello All, I am attempting to us os.walk to populate two lists with values from a directory. The first list contains all the files in the directory and subdirectories. The second list contains only the files in the subdirectories. Here is the code: import os # list of matching files allfiles = [] #store all files found subfiles = [] # subdir for root,dir,files in os.walk("H:/python_experiments", f1): # this list has the files in all directories and subdirectories filelist = [ os.path.join(root,fi) for fi in files if fi.endswith(".py") or fi.endswith(".txt") ] for f in filelist: allfiles.append(f) # split the root s= root.split(('\\') or ('\/')) print 's ', print s # assign the last value to end to come to values in dir end= s[-1] print 'end ', print end print '\n' # this list contains only the files in subdirectories for d in dir: if end == d: print 'subdir % s' % (end) sublist = [ os.path.join(root, fi) for fi in files if fi.endswith(".py") or fi.endswith(".txt")] for f in sublist: subfiles.append(f) for i in subfiles: print 'subfile', i for i in allfiles: print "file ", i The allfiles list is populated, but the subfiles list is not. Any Suggetions ? I think you were trying to make this harder than it actually is. Here is a tested script that works for me. import os basePath = 'c:/Python25' allfiles = [] subfiles = [] for root, dirs, files in os.walk(basePath): for f in files: if f.endswith('.txt') or f.endswith('.py'): allfiles.append(os.path.join(root, f)) if root != basePath: # I'm in a subdirectory subfiles.append(os.path.join(root, f)) print "allfiles=", allfiles print print "subfiles=", subfiles print print "len(allfiles)=", len(allfiles) print "len(subfiles)=", len(subfiles) -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
serach file for regexp, return if found?
i want to search a document for a particular regexp and then store that regexp to a file. but search and match only returns matchobjects(what are those anyway? i dont get what to do with them, do they contain true/false, stringposition etc?) how do i do: for rows in file: print regexp.find ## or something equiavlent -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On May 22, 6:14 pm, cm_gui <[EMAIL PROTECTED]> wrote: > I've yet to see a web application written in Python which is really > fast. I bet you have a slow dial-up connection. -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __getitem__
actually i ddin't think about the fact that you're overloading dict, which can already take multiple values in getitem so how about class crazy: pass and then in your dict class: def __getitem__(*args): if args[-1] is crazy: return self.get(args[:-1])*5 else: return self.get(args) and then print foo[1,2] #not crazy print foo[1,2,crazy] #crazy I *think* that would work "Andreas Matthias" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The following code doesn't run but I hope you get what I > am trying to do. > > > class my_dict (dict): > >def __getitem__ (self, key, crazy = False): >if crazy == True: >return 5 * self.get(key) >else: >return self.get(key) > > > foo = my_dict() > foo['a'] = 123 > > print foo['a'] > print foo['a', crazy = True] > > > Is it somehow possible to overload __getitem__ with an additional > argument? Are there other possibilities to achiev this? Or is > the only solution to this to write a normal function call > `def my_get (self, key, crazy=False)'? > > > Ciao > Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes help
On May 23, 12:33 am, gianluca <[EMAIL PROTECTED]> wrote: > Hy, > I need help about use dll with ctypes. I've compiled my dll C library > and I copied it in c:\windows\system32. When I load it with > "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem all OK but > python don't see the dll function. with dir(myDLL) I've only this: > ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', > '__getattr__', '__getattribute__', '__getitem__', '__hash__', > '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', > '__repr__', '__setattr__', '__str__', '__weakref__', '_handle', > '_name'] I see nothing wrong here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
cm_gui wrote: Python is slow.Almost all of the web applications written in Python are slow. Zope/Plone is slow, sloow, so very slooow. Even Google Apps is not faster. Neither is Youtube. Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster than Python. Okay, they probably use caching or some code compilation -- but Google Apps and those Zope sites probably also use caching. I've yet to see a web application written in Python which is really fast. You are just dead wrong about this. Bad programmers will write slow software in any language. There are some HUGE sites using Zope. I think much of Google's software is written in Python. I have programs that have surprised me with their speed. If your Python program is slow, you have almost assuredly approached it with a wrong method or algorithm. www.websafe.com is completely written in Python and we support thousands of users uploading data simultaneously at wire speed (and that includes AES-256 encryption on our end). -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __getitem__
"inhahe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > crazy = True > print foo['a',crazy] > just to clarify, you could use it like: crazy = "I'm crazy" #this only has to be done once print foo['a'] #not crazy print foo['a',crazy] #crazy (this may be totally unPythonic, i don't know.) -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the Write method of ElementTree??
On May 23, 6:56 am, [EMAIL PROTECTED] wrote: > I'm messing around with trying to write an xml file using > xml.etree.ElementTree. All the examples on the internet show the use > of ElementTree.write(), although when I try to use it it's not > available, gives me ... > >ElementTree(sectionElement).write("section.xml") > TypeError: 'module' object is not callable > > I'm new to python, so I think I'm doing something wrong.. any > thoughts? > > Thanks.' > > See code below: > > # Create xml structure > sectionElement = ElementTree.Element("section") > > # step through feed result and create elements for each article - > result[article] > for article in feedResult: > articleElement = ElementTree.Element("article") > > titleElement = ElementTree.SubElement(articleElement, "title") > titleElement.text = article['title'] > > bodyElement = ElementTree.SubElement(articleElement, "body") > bodyElement.text = article['body'] > > sectionElement.append(articleElement) > > #print ElementTree.tostring(sectionElement) > ElementTree(sectionElement).write("section.xml") It's complaining about ElementTree(whatever) As it says, you are trying to call a module. Looks like you need: sectionElement.write("section.xml") HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __getitem__
it seems like you can't do it exactly the way you're trying but you could do this def __getitem__(*args): if len(args) > 1 and args[1]: return self.get(args[0]) * 5 return self.get(args[0]) then you would use it like print foo['a'] print foo['a',True] or even print foo['a',"crazy"] if you wanted. or crazy = True print foo['a',crazy] "Andreas Matthias" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The following code doesn't run but I hope you get what I > am trying to do. > > > class my_dict (dict): > >def __getitem__ (self, key, crazy = False): >if crazy == True: >return 5 * self.get(key) >else: >return self.get(key) > > > foo = my_dict() > foo['a'] = 123 > > print foo['a'] > print foo['a', crazy = True] > > > Is it somehow possible to overload __getitem__ with an additional > argument? Are there other possibilities to achiev this? Or is > the only solution to this to write a normal function call > `def my_get (self, key, crazy=False)'? > > > Ciao > Andreas -- http://mail.python.org/mailman/listinfo/python-list
ctypes help
Hy, I need help about use dll with ctypes. I've compiled my dll C library and I copied it in c:\windows\system32. When I load it with "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem all OK but python don't see the dll function. with dir(myDLL) I've only this: ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_handle', '_name'] Could anybody help me Thanks Gianluca -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
Dave Parker wrote: Or just: If command is "quit" ... Hmmm. In Flaming Thunder, I'm using "is" (and "is an", "is a", etc) for assigning and checking types. For example, to read data from a file and check for errors: Read data from "input.txt". If data is an error then go to ... Hey Dave, Does this mean that Flaming Thunder requires explicit checking rather than offering exceptions? Cheers, Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
cm_gui wrote: Python is slow. It ain't C++, but it ain't a punch card either... somewhere in between. I find it suitable for lots of stuff. I use C++ when performance really matters tho... right tool for the job. Learn a good interpreted language (Pyhton) and a good compiled language (C or C++) and you'll be just fine. Until then, quit bitching. -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
I don't like php. I tried it once and I had it sort a list, but the list was apparently too long for its sorting function because it just sorted the first so-many elements of it and left the rest in order, and didn't generate any error. I like a language that's actually determined by what you tell it to do. I hear it has a lot of security issues too. I'm not sure that php *runs* faster than python, having seen benchmarks, but it certainly loads faster. Maybe not so much of a difference once python25.dll is already in the cache though (speaking from a windows perspective). because when i load a program it can take a while but it's pretty quick if i'd just loaded one recently. but you don't necessarily have to load python for each page rendering anyway. I like the Python language a lot better than php. but I just really like Python. php mixes html and code out-of-the-box (sort of.. i guess it's more like a reversal of which one is explicit)... if you use Python you should look into a 'templating engine' like mako. i use cheetah, but mako is supposed to be better. i think Python is the easiest language to learn, with the possible exception of qbasic (just because making multidimensional arrays in python isnt that obvious, although maybe it is using numpy, i've never tried it). Python isn't as easy as basic if you use/have to read the more advanced features, but those aren't even available in basic. so I find it a comfortable learning curve. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2 different versions of python compiling files.
On May 22, 3:56 pm, TkNeo <[EMAIL PROTECTED]> wrote: > On May 22, 2:44 pm, Hans Nowak <[EMAIL PROTECTED]> > wrote: > > > > > TkNeo wrote: > > > I am trying to upgrade from python 2.3 to 2.4 but not all machines can > > > be upgraded. Can you guys tell me if this scenario is possible. > > > > 1. Any machine that uses .py files that use libraries that require 2.4 > > > will have 2.4 on it. > > > 2. rest of the machines will have 2.3 > > > > now there is a shared drive. lets say i write a new library called > > > testlib.py and put it on the shared drive .. when a script uses it > > > from a 2.4 based machine, it will generate a testlib.pyc and leave it > > > on the shared drive. going forward that .pyc is used until the > > > original lib is changed. now lets say a 2.3 based machine is trying to > > > use that lib. it will try to use that pyc file which was compiled by > > > py2.4. will it work or crash ? > > > It should work, as long as the original .py file is still there. Each > > Python > > version will check for a .pyc file *corresponding to that version* (e.g. > > Python > > 2.4 will look for a .pyc file compiled with 2.4), and create one if it > > doesn't > > exist, overwriting any existing .pyc file in the process. > > > If the original .py file is *not* there, it will most likely not work. If > > you > > try to import a .pyc file with the wrong version number, you get something > > like > > this: > > > >>> import foo > > Traceback (most recent call last): > >File "", line 1, in ? > > ImportError: Bad magic number in foo.pyc > > > I'm not sure what would happen if multiple Pythons try to write a .pyc file > > at > > the same time, though... > > > -- > > Hans Nowak (zephyrfalcon at gmail dot org)http://4.flowsnake.org/ > > The original .py will always be there but you know what, multiple > python versions from different computers do access that one library at > the same time. > > Anyone know a possible solution ? What error message are you getting? -- http://mail.python.org/mailman/listinfo/python-list
Overloading __getitem__
The following code doesn't run but I hope you get what I am trying to do. class my_dict (dict): def __getitem__ (self, key, crazy = False): if crazy == True: return 5 * self.get(key) else: return self.get(key) foo = my_dict() foo['a'] = 123 print foo['a'] print foo['a', crazy = True] Is it somehow possible to overload __getitem__ with an additional argument? Are there other possibilities to achiev this? Or is the only solution to this to write a normal function call `def my_get (self, key, crazy=False)'? Ciao Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I make a copy of my class object?
"Marlin Rowley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a class object which has the usual data members and functions. > I'm trying to make a copy of this class (which includes wx.Bitmap objects) > but deepcopy() doesn't seem to work. How would I do this? Are you trying to make a copy of the "class object" or of a class instance? What error message are you getting when you call deepcopy() on this object? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using os.walk to return files in subdirectories
On May 22, 5:24 pm, dj <[EMAIL PROTECTED]> wrote: ...snip... > for d in dir: > if end == d: dir is the list of subdirs of the current dir, and the current dir is NOT a subdir of itself so end == dir is never true Are you trying to get a list per subdir? cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
Hallöchen! Matthew Woodcraft writes: > [...] > > At one time, Guido was very keen on the idea of Python as a > language to introduce non-programmers to (under the 'Computer > Programming for Everybody' slogan). > > I think it's rather a shame that this has more-or-less fallen by > the wayside. There are lots of people out there producing buggy > spreadsheets to do things that would be easier to do in a > programming language. I don't think so. It's still reasonably simple to write short Python programs for e.g. the analysis of measurement results. But people simply don't trust cheap non-point'n'click programs which don't occupy two shelves in the bookstore. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] (See http://ime.webhop.org for further contact info.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Shell-independent *nix setup script
[EMAIL PROTECTED] wrote: Hi, Is it worthwhile maintaining a production application setup script in Python as opposed to shell-script? I do not think so. Perhaps 'in conjunction with', but not 'opposed to'... sh is the lowest common denominator of shells. Script for sh and your script will run on most any Unix. Python is gaining acceptance, but is still not present everywhere by default... Solaris for example. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using os.walk to return files in subdirectories
Hello All, I am attempting to us os.walk to populate two lists with values from a directory. The first list contains all the files in the directory and subdirectories. The second list contains only the files in the subdirectories. Here is the code: import os # list of matching files allfiles = [] #store all files found subfiles = [] # subdir for root,dir,files in os.walk("H:/python_experiments", f1): # this list has the files in all directories and subdirectories filelist = [ os.path.join(root,fi) for fi in files if fi.endswith(".py") or fi.endswith(".txt") ] for f in filelist: allfiles.append(f) # split the root s= root.split(('\\') or ('\/')) print 's ', print s # assign the last value to end to come to values in dir end= s[-1] print 'end ', print end print '\n' # this list contains only the files in subdirectories for d in dir: if end == d: print 'subdir % s' % (end) sublist = [ os.path.join(root, fi) for fi in files if fi.endswith(".py") or fi.endswith(".txt")] for f in sublist: subfiles.append(f) for i in subfiles: print 'subfile', i for i in allfiles: print "file ", i The allfiles list is populated, but the subfiles list is not. Any Suggetions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
<[EMAIL PROTECTED]> wrote: > So it seems like you're designing a language for non-programmers. > That's good, I've never heard about anyone so interested in teaching > programming for kids and non-programmers. But in that case, you > shouldn't even be comparing it to Python. At one time, Guido was very keen on the idea of Python as a language to introduce non-programmers to (under the 'Computer Programming for Everybody' slogan). I think it's rather a shame that this has more-or-less fallen by the wayside. There are lots of people out there producing buggy spreadsheets to do things that would be easier to do in a programming language. -M- -- http://mail.python.org/mailman/listinfo/python-list
How do I make a copy of my class object?
All: I have a class object which has the usual data members and functions. I'm trying to make a copy of this class (which includes wx.Bitmap objects) but deepcopy() doesn't seem to work. How would I do this? -M _ E-mail for the greater good. Join the i’m Initiative from Microsoft. http://im.live.com/Messenger/IM/Join/Default.aspx?source=EML_WL_ GreaterGood-- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
Hi Marc, "Marc Christiansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm not sure I would recommend it, but try: > [v for x in range(4) for v in (x, 2 * x)] That certainly works... and it almost seems like a bit less of a hack (if perhaps somewhat harder to read) than the "sum" approach to flattening? > A similar solution as above should work. This is what I came up with: >>> list1=[1,2,3] >>> list2=[4,5,6] >>> [j for (i,m) in enumerate(list1) for j in (m,list2[i])] [1, 4, 2, 5, 3, 6] Not exactly "clean" due to having to enumerate list1 to get the index for list2. There may be a better method, of course -- so far I like Petter Otten's approach. Thanks for the help, ---Joel -- http://mail.python.org/mailman/listinfo/python-list
Bug in ssl-object library reference page or in ssl-object code?
According to http://docs.python.org/lib/ssl-objects.html 17.2.2 SSL Objects SSL objects have the following methods. read([n]) If n is provided, read n bytes from the SSL connection, otherwise read until EOF. The return value is a string of the bytes read. The behavior I observer when n is not provided doesn't agree with the description. When I call read(), it appears that I get whatever data is currently available. It does not read until EOF. This seems to agree with the comment on the "example" page: http://docs.python.org/lib/socket-example.html # Read a chunk of data. Will not necessarily # read all the data returned by the server. data = ssl_sock.read() If read() did indeed read until EOF, then it would always read all of the data returned by the server. Is this a bug in the doc or in the code? -- Grant Edwards grante Yow! How do I get HOME? at visi.com -- http://mail.python.org/mailman/listinfo/python-list
where is the Write method of ElementTree??
I'm messing around with trying to write an xml file using xml.etree.ElementTree. All the examples on the internet show the use of ElementTree.write(), although when I try to use it it's not available, gives me ... ElementTree(sectionElement).write("section.xml") TypeError: 'module' object is not callable I'm new to python, so I think I'm doing something wrong.. any thoughts? Thanks.' See code below: # Create xml structure sectionElement = ElementTree.Element("section") # step through feed result and create elements for each article - result[article] for article in feedResult: articleElement = ElementTree.Element("article") titleElement = ElementTree.SubElement(articleElement, "title") titleElement.text = article['title'] bodyElement = ElementTree.SubElement(articleElement, "body") bodyElement.text = article['body'] sectionElement.append(articleElement) #print ElementTree.tostring(sectionElement) ElementTree(sectionElement).write("section.xml") -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
"inhahe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > i figured out a solution > > sum([x,2*x] for x in range(4)],[]) #not tested Nice... thanks; I probably had seen code using 'sum' to flatten but hadn't actually understood how it worked. After playing around some it's now clear... (Add one more opening bracket to your solution to make the interpreter happy -- I know you know this and it was missed only due to not actually trying it ought) ---Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> A slightly similar problem: If I want to "merge," say, list1=[1,2,3] ... items = [None] * 6 items[::2] = 1,2,3 items[1::2] = 4,5,6 items > [1, 4, 2, 5, 3, 6] Thanks Peter, that's pretty clean -- I like it! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
Mel <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On May 22, 10:30??am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > >> Dave Parker <[EMAIL PROTECTED]> wrote: > >> > But after getting input from children and teachers, etc, it started > >> > feeling right. > >> > >> > For example, consider the two statements: > >> > >> > x = 8 > >> > x = 10 > >> > >> > The reaction from most math teachers (and kids) was "one of those is > >> > wrong because x can't equal 2 different things at the same time". > >> > >> This is a common feature in functional languages... > >> > >> Eg > >> > >> Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] > >> [async-threads:0] [kernel-poll:false] > >> > >> Eshell V5.6.2 ??(abort with ^G) > >> 1> X = 8. > >> 8 > >> 2> X = 10. > >> ** exception error: no match of right hand side value 10 > >> 3> > >> > >> That error message is the erlang interpreter saying "Hey I know X is > >> 8, and you've said it is 10 - that can't be right", which is pretty > >> much what math teachers say too... > > > > Are you saying that erlang treats 1> as an assignment, yet > > treats 2> as a comparison? > > > > That's inconsistent. No wonder nobody uses erlang. > > In Prolog terms, they're both unification. If X has never been defined you > can define it as 8 with no chance of contradicting anything. Once X is 8, > the proposition "X is 10" is false. > > I act as though Erlang thinks the same. My Erlang chops aren't as good as my > Prolog chops were. I had to look up the definition of unification, but yes you are right, erlang and prolog seem mean roughly the same thing by the = sign. It is called the pattern matching operator in erlang. >From Armstrong's book: The expression Pattern = Expression causes Expression to be evaluated and the result matched against Pattern. The match either succeeds or fails. If the match succeeds any variables occurring in Pattern become bound. It is a very powerful idea and one which (along with the concurrency and message passing from Erlang) has been implemented for python :- http://candygram.sourceforge.net/ I've been reading the Erlang book and I have to say it has given me a lot of insight into python... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
Joel Koltner <[EMAIL PROTECTED]> wrote: > Is there an easy way to get a list comprehension to produce a flat > list of, say, [x,2*x] for each input argument? > > E.g., I'd like to do something like: > > [ [x,2*x] for x in range(4) ] > > ...and receive > > [ 0,0,1,2,2,4,3,6] > > ...but of course you really get a list of lists: > > [[0, 0], [1, 2], [2, 4], [3, 6]] I'm not sure I would recommend it, but try: [v for x in range(4) for v in (x, 2 * x)] > A slightly similar problem: If I want to "merge," say, list1=[1,2,3] > with list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way > with "zip" to do so? A similar solution as above should work. Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
On Thu, 22 May 2008 15:29:42 -0400, inhahe wrote: > "Joel Koltner" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Is there an easy way to get a list comprehension to produce a flat list >> of, say, [x,2*x] for each input argument? >> >> E.g., I'd like to do something like: >> >> [ [x,2*x] for x in range(4) ] >> >> ...and receive >> >> [ 0,0,1,2,2,4,3,6] >> >> ...but of course you really get a list of lists: >> >> [[0, 0], [1, 2], [2, 4], [3, 6]] >> >> I'm aware I can use any of the standard "flatten" bits of code to turn >> this back into what I want, but I was hoping there's some way to avoid >> the "lists of lists" generation in the first place? >> >> A slightly similar problem: If I want to "merge," say, list1=[1,2,3] >> with list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way >> with "zip" to do so? >> >> Thanks, >> ---Joel >> >> > i figured out a solution > > sum([x,2*x] for x in range(4)],[]) #not tested sum(zip(list1,list2),()) > #not tested > > (you did say you knew of ways to flatten, but i dunno if you knew of > that way or not) > > as an aside, i wish that sum didn't have to take the second parameter. > it's kind of superfluous. it can just use the first item as the initial > value instead of 0 when no initial value is specified. it would be a > little complex to do without putting a conditional in your main loop and > slowing it down, but it could be done. If you don't want the second parameter use reduce(): >>> reduce(operator.add, ([x, x*2] for x in xrange(4))) [0, 0, 1, 2, 2, 4, 3, 6] >>> reduce(operator.add, zip([1,2,3],[4,5,6])) (1, 4, 2, 5, 3, 6) or: >>> reduce(lambda x, y: x.extend(y) or x, ([x, x*2] for x in xrange(4))) [0, 0, 1, 2, 2, 4, 3, 6] -- Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: Struct usage and varying sizes of h, l, etc
Ethan Furman wrote: Next question: when using struct.pack to store an integer, I get a deprecation warning if the int is too big... I would rather have an error. Is there a setting somewhere that controls this? http://docs.python.org/dev/library/warnings -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: 2 different versions of python compiling files.
On May 22, 2:44 pm, Hans Nowak <[EMAIL PROTECTED]> wrote: > TkNeo wrote: > > I am trying to upgrade from python 2.3 to 2.4 but not all machines can > > be upgraded. Can you guys tell me if this scenario is possible. > > > 1. Any machine that uses .py files that use libraries that require 2.4 > > will have 2.4 on it. > > 2. rest of the machines will have 2.3 > > > now there is a shared drive. lets say i write a new library called > > testlib.py and put it on the shared drive .. when a script uses it > > from a 2.4 based machine, it will generate a testlib.pyc and leave it > > on the shared drive. going forward that .pyc is used until the > > original lib is changed. now lets say a 2.3 based machine is trying to > > use that lib. it will try to use that pyc file which was compiled by > > py2.4. will it work or crash ? > > It should work, as long as the original .py file is still there. Each Python > version will check for a .pyc file *corresponding to that version* (e.g. > Python > 2.4 will look for a .pyc file compiled with 2.4), and create one if it doesn't > exist, overwriting any existing .pyc file in the process. > > If the original .py file is *not* there, it will most likely not work. If you > try to import a .pyc file with the wrong version number, you get something > like > this: > > >>> import foo > Traceback (most recent call last): >File "", line 1, in ? > ImportError: Bad magic number in foo.pyc > > I'm not sure what would happen if multiple Pythons try to write a .pyc file at > the same time, though... > > -- > Hans Nowak (zephyrfalcon at gmail dot org)http://4.flowsnake.org/ The original .py will always be there but you know what, multiple python versions from different computers do access that one library at the same time. Anyone know a possible solution ? -- http://mail.python.org/mailman/listinfo/python-list
Shell-independent *nix setup script
Hi, Is it worthwhile maintaining a production application setup script in Python as opposed to shell-script? The main goal of this setup script is to sniff a user's environment and export environment variables to the calling (parent) process. Either way, some file would need to be sourced into the user's environment, so why not use a richer language where the setup logic is independent of the user's shell being used. Thanks for your feedback, Scott -- http://mail.python.org/mailman/listinfo/python-list
Re: Using MySQLdb to select into the local file
Nikhil wrote: I am using the MySQLdb python module. I have a table named 'testing' with few columns, under the 'test' database, what is hosted on a remote mysql server. I want to run the following query to get a comma-separated information from the table LOCK TABLES foo READ; SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM 'testing' UNLOCK TABLES; ..the query is running fine, but what I am noticing is /tmp/result.txt is getting created locally on a mysqld running machine but not on the client(python program) using the MySQLdb module. Unfortunately, while there is LOAD DATA LOCAL INFILE, which reads a file on the client, there is no SELECT INTO LOCAL OUTFILE. Actually, you probably want to turn off the FILE privilege for your MySQL. That blocks LOAD DATA INFILE and SELECT INTO OUTFILE, generally considered a good idea because those commands can access arbitrary file names. Also, if you're still using LOCK TABLES and UNLOCK TABLES, read up on InnoDB and transactions. Typically, you do something like this: import MySQLdb import csv def writedb(db, filename) : try : outcsv = csv.writer(filename) # output object for CSV cursor = db.cursor() cursor.execute("SELECT a,b,a+b FROM testing") while True :# do all rows row = cursor.fetchone() # get a tuple for one row if row is None :# if end of rows break # done outcsv.writerow(row)# write row in CSV format db.commit() # release locks except MySQLdb.OperationalError, message: print "Database trouble: ", message # handle any db problems raise # reraise exception hostname="???"# fill in appropriately user="???" password="???" db = MySQLdb.connect(host=hostname, # open database user=username, passwd=password, db=databasename) writedb(db, '/tmp/result.txt') # do it === Note that this is ASCII-oriented; if you Unicode, you need extra params to "connect". Also, the CSV module doesn't do Unicode well as yet. Make sure the "outcsv" object goes out of scope before you try to read the file, so the file gets flushed and closed. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: 2 different versions of python compiling files.
TkNeo wrote: I am trying to upgrade from python 2.3 to 2.4 but not all machines can be upgraded. Can you guys tell me if this scenario is possible. 1. Any machine that uses .py files that use libraries that require 2.4 will have 2.4 on it. 2. rest of the machines will have 2.3 now there is a shared drive. lets say i write a new library called testlib.py and put it on the shared drive .. when a script uses it from a 2.4 based machine, it will generate a testlib.pyc and leave it on the shared drive. going forward that .pyc is used until the original lib is changed. now lets say a 2.3 based machine is trying to use that lib. it will try to use that pyc file which was compiled by py2.4. will it work or crash ? It should work, as long as the original .py file is still there. Each Python version will check for a .pyc file *corresponding to that version* (e.g. Python 2.4 will look for a .pyc file compiled with 2.4), and create one if it doesn't exist, overwriting any existing .pyc file in the process. If the original .py file is *not* there, it will most likely not work. If you try to import a .pyc file with the wrong version number, you get something like this: >>> import foo Traceback (most recent call last): File "", line 1, in ? ImportError: Bad magic number in foo.pyc I'm not sure what would happen if multiple Pythons try to write a .pyc file at the same time, though... -- Hans Nowak (zephyrfalcon at gmail dot org) http://4.flowsnake.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Flaming Thunder
On 22 mai, 18:56, Mensanator <[EMAIL PROTECTED]> wrote: > On May 22, 10:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > > Dave Parker <[EMAIL PROTECTED]> wrote: > > > But after getting input from children and teachers, etc, it started > > > feeling right. > > > > For example, consider the two statements: > > > > x = 8 > > > x = 10 > > > > The reaction from most math teachers (and kids) was "one of those is > > > wrong because x can't equal 2 different things at the same time". > > > This is a common feature in functional languages... > > > Eg > > > Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] > > [async-threads:0] [kernel-poll:false] > > > Eshell V5.6.2 (abort with ^G) > > 1> X = 8. > > 8 > > 2> X = 10. > > ** exception error: no match of right hand side value 10 > > 3> > > > That error message is the erlang interpreter saying "Hey I know X is > > 8, and you've said it is 10 - that can't be right", which is pretty > > much what math teachers say too... > > Are you saying that erlang treats 1> as an assignment, yet > treats 2> as a comparison? Nope. Both are treated as pattern matching. The first one binds X because it's by that time a free variable, the second fails because it doesn't match. > That's inconsistent. That's consistent when you understand how Erlang works. > No wonder nobody uses erlang. Strange enough, it seems that more and more developpers and company start to look at Erlang as a possible solution to massive scaling problems. > Why isn't erlang smart, like Python, and avoid such confusion? Erlang *is* smart. It's just totally different from Python. And there's no confusion here (except on your side...). -- http://mail.python.org/mailman/listinfo/python-list
Re: Restarting a program
On May 22, 11:58 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On May 22, 1:38 pm, Geoldr <[EMAIL PROTECTED]> wrote: > > > > > On May 22, 10:07 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > > > > On May 22, 10:59 am, Geoldr <[EMAIL PROTECTED]> wrote: > > > > > Hello all, I have written a simple program, and at the end of it, > > > > instead of it closing I would like it to restart from the beggining. > > > > Is there a way to do this? Put my code into a class function, or > > > > something? > > > > I guess I could do a while loop, but I think if there is a way to run > > > > my code if it's in a class would be an easier option. I can't seem to > > > > find many guides online but maybe I have not been looking in the right > > > > places. > > > > > Anybody have any ideas? > > > > Putting your code in a function or class is probably the way to go. > > > When I was doing C++, we'd just use a while loop for simple stuff, > > > though. > > > > It really shouldn't be all that hard to tell the code to call up the > > > beginning of the program again. > > > > Mike > > > That's what I am trying to figure out, but it doesn't seem to work. Do > > you have any example code of classes/functions that work for you? > > No...but I through some concept code together that does the basics: > > > > def repeater(): > > for i in range(10): > print i > > def main(): > ret = 'Y' > while 1: > if ret.upper() == 'Y': > repeater() > else: > print 'Program finished...goodbye!' > break > ret = raw_input('Do you want to continue? (Y/N)') > > if __name__ == '__main__': > main() > > > > I found that using the while was the easiest to create on short > notice. You could probably do it with recursion too, but I'm not > especially good at that. > > Another idea is to have some kind of sentinel value that both > functions can access and use it somehow to tell whether or not to > repeat. > > Hope that helps you get going. > > Mike Thank you, the "def" option works the best. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
"Joel Koltner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there an easy way to get a list comprehension to produce a flat list > of, say, [x,2*x] for each input argument? > > E.g., I'd like to do something like: > > [ [x,2*x] for x in range(4) ] > > ...and receive > > [ 0,0,1,2,2,4,3,6] > > ...but of course you really get a list of lists: > > [[0, 0], [1, 2], [2, 4], [3, 6]] > > I'm aware I can use any of the standard "flatten" bits of code to turn > this back into what I want, but I was hoping there's some way to avoid the > "lists of lists" generation in the first place? > > A slightly similar problem: If I want to "merge," say, list1=[1,2,3] with > list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way with "zip" > to do so? > > Thanks, > ---Joel > i figured out a solution sum([x,2*x] for x in range(4)],[]) #not tested sum(zip(list1,list2),()) #not tested (you did say you knew of ways to flatten, but i dunno if you knew of that way or not) as an aside, i wish that sum didn't have to take the second parameter. it's kind of superfluous. it can just use the first item as the initial value instead of 0 when no initial value is specified. it would be a little complex to do without putting a conditional in your main loop and slowing it down, but it could be done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
Joel Koltner wrote: > Is there an easy way to get a list comprehension to produce a flat list > of, say, [x,2*x] for each input argument? > > E.g., I'd like to do something like: > > [ [x,2*x] for x in range(4) ] > > ...and receive > > [ 0,0,1,2,2,4,3,6] > > ...but of course you really get a list of lists: > > [[0, 0], [1, 2], [2, 4], [3, 6]] > > I'm aware I can use any of the standard "flatten" bits of code to turn > this back into what I want, but I was hoping there's some way to avoid the > "lists of lists" generation in the first place? >>> [x*y for x in range(4) for y in 1,2] [0, 0, 1, 2, 2, 4, 3, 6] > A slightly similar problem: If I want to "merge," say, list1=[1,2,3] with > list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way with "zip" > to do so? >>> items = [None] * 6 >>> items[::2] = 1,2,3 >>> items[1::2] = 4,5,6 >>> items [1, 4, 2, 5, 3, 6] Peter -- http://mail.python.org/mailman/listinfo/python-list
Using MySQLdb to select into the local file
I am using the MySQLdb python module. I have a table named 'testing' with few columns, under the 'test' database, what is hosted on a remote mysql server. I want to run the following query to get a comma-seperated information from the table LOCK TABLES foo READ; SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM 'testing' UNLOCK TABLES; ..the query is running fine, but what I am noticing is /tmp/result.txt is getting created locally on a mysqld running machine but not on the client(python program) using the MySQLdb module. I am wondering if anyone has gone through this before and made some arrangements to iterate over the data but get the /tmp/result.txt generated locally on the client machine? On the local or the server file, from http://dev.mysql.com/doc/refman/5.0/en/select.html --- The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some client host other than the server host, you cannot use SELECT ... INTO OUTFILE. In that case, you should instead use a command such as mysql -e "SELECT ..." > file_name to generate the file on the client host. --- So, what is the equivalent of using '-e' mysql commandline option in the MySQLdb python module? I am sorry if this is supposed to go to only MySQL, but not really sure so copying the relevant assumed. Thanks, Nikhil -- http://mail.python.org/mailman/listinfo/python-list
Re: Producing multiple items in a list comprehension
Joel Koltner wrote: Is there an easy way to get a list comprehension to produce a flat list of, say, [x,2*x] for each input argument? E.g., I'd like to do something like: [ [x,2*x] for x in range(4) ] ...and receive [ 0,0,1,2,2,4,3,6] ...but of course you really get a list of lists: [[0, 0], [1, 2], [2, 4], [3, 6]] I'm aware I can use any of the standard "flatten" bits of code to turn this back into what I want, but I was hoping there's some way to avoid the "lists of lists" generation in the first place? A slightly similar problem: If I want to "merge," say, list1=[1,2,3] with list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way with "zip" to do so? Thanks, ---Joel -- http://mail.python.org/mailman/listinfo/python-list For the first part: def gen(n): for i in xrange(n): yield i yield 2*i print list(gen(4)) [0, 0, 1, 2, 2, 4, 3, 6] gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: HTMLParser error
On May 22, 9:59 am, alex23 <[EMAIL PROTECTED]> wrote: > On May 22, 6:22 pm, [EMAIL PROTECTED] wrote: > > > Still getting very odd errors though, this being the latest: > > > Traceback (most recent call last): > > File "spider.py", line 38, in > > [...snip...] > > raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) > > httplib.InvalidURL: nonnumeric port: '' > > Okay. What I did was put some output in your Spider.parse method: > > def parse(self, page): > try: > print 'http://' + page > self.feed(urlopen('http://' + page).read()) > except HTTPError: > print 'Error getting page source' > > And here's the output: > > >python spider.py > What site would you like to scan?http://www.google.com > http://www.google.com > http://http://images.google.com.au/imghp?hl=en&tab=wi > > The links you're finding on each page already have the protocol > specified. I'd remove the 'http://' addition from parse, and just add > it to 'site' in the main section. > > if __name__ == '__main__': > s = Spider() > site = raw_input("What site would you like to scan? http://";) > site = 'http://' + site > s.crawl(site) > > > Also could you explain why I needed to add that > > HTMLParser.__init__(self) line? Does it matter that I have overwritten > > the __init__ function of spider? > > You haven't overwritten Spider.__init__. What you're doing every time > you create a Spider object is first get HTMLParser to initialise it as > it would any other HTMLParser object - which is what adds the .rawdata > attribute to each HTMLParser instance - *and then* doing the Spider- > specific initialisation you need. > > Here's an abbreviated copy of the actual HTMLParser class featuring > only its __init__ and reset methods: > > class HTMLParser(markupbase.ParserBase): > def __init__(self): > """Initialize and reset this instance.""" > self.reset() > > def reset(self): > """Reset this instance. Loses all unprocessed data.""" > self.rawdata = '' > self.lasttag = '???' > self.interesting = interesting_normal > markupbase.ParserBase.reset(self) > > When you initialise an instance of HTMLParser, it calls its reset > method, which sets rawdata to an empty string, or adds it to the > instance if it doesn't already exist. So when you call > HTMLParser.__init__(self) in Spider.__init__(), it executes the reset > method on the Spider instance, which it inherits from HTMLParser... > > Are you familiar with object oriented design at all? If you're not, > let me know and I'll track down some decent intro docs. Inheritance is > a pretty fundamental concept but I don't think I'm doing it justice. Nope, this is my first experience with object oriented programming, only been learning python for a few weeks but it seemed simple enough to inspire me to be a bit ambitious. If you could hook me up with some good docs that would be great. I was about to but a book on python, specifically OO based, but il look at these docs first. I understand most of the concepts of inheritance, just not ever used them before. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is math.pi slightly wrong?
On Thu, May 22, 2008 at 2:53 PM, Mensanator <[EMAIL PROTECTED]> wrote: > On May 22, 11:32 am, "Dutton, Sam" <[EMAIL PROTECTED]> wrote: >> I've noticed that the value of math.pi -- just entering it at the >> interactive prompt -- is returned as 3.1415926535897931, whereas (as every >> pi-obsessive knows) the value is 3.1415926535897932... (Note the 2 at the >> end.) >> >> Is this a precision issue, or from the underlying C, or something else? How >> is math.pi calculated? > > If you actually need that many digits, use a different library. > import gmpy > print gmpy.pi(64) # 64 bit precision > 3.14159265358979323846 print gmpy.pi(128) # 128 bit precision > 3.141592653589793238462643383279502884197 print gmpy.pi(16384) # 16384 bit precision > 3.14159265358979323846264338327950288419716939937510582097494459 > 2307816406286208998628034825342117067982148086513282306647093844 > 6095505822317253594081284811174502841027019385211055596446229489 > 5493038196442881097566593344612847564823378678316527120190914564 > 8566923460348610454326648213393607260249141273724587006606315588 > 1748815209209628292540917153643678925903600113305305488204665213 > 8414695194151160943305727036575959195309218611738193261179310511 > 8548074462379962749567351885752724891227938183011949129833673362 > 4406566430860213949463952247371907021798609437027705392171762931 > 7675238467481846766940513200056812714526356082778577134275778960 > 9173637178721468440901224953430146549585371050792279689258923542 > 019956112129021960864034418159813629774771309960518707211349 > 9837297804995105973173281609631859502445945534690830264252230825 > 3344685035261931188171010003137838752886587533208381420617177669 > 1473035982534904287554687311595628638823537875937519577818577805 > 3217122680661300192787661119590921642019893809525720106548586327 > 8865936153381827968230301952035301852968995773622599413891249721 > 7752834791315155748572424541506959508295331168617278558890750983 > 8175463746493931925506040092770167113900984882401285836160356370 > 7660104710181942955596198946767837449448255379774726847104047534 > 6462080466842590694912933136770289891521047521620569660240580381 > 5019351125338243003558764024749647326391419927260426992279678235 > 4781636009341721641219924586315030286182974555706749838505494588 > 5869269956909272107975093029553211653449872027559602364806654991 > 198818347977535663698074265425278625518184175746728909279380 > 0081647060016145249192173217214772350141441973568548161361157352 > 5521334757418494684385233239073941433345477624168625189835694855 > 6209921922218427255025425688767179049460165346680498862723279178 > 6085784383827967976681454100953883786360950680064225125205117392 > 9848960841284886269456042419652850222106611863067442786220391949 > 4504712371378696095636437191728746776465757396241389086583264599 > 5813390478027590099465764078951269468398352595709825822620522489 > 4077267194782684826014769909026401363944374553050682034962524517 > 4939965143142980919065925093722169646151570985838741059788595977 > 2975498930161753928468138268683868942774155991855925245953959431 > 0499725246808459872736446958486538367362226260991246080512438843 > 9045124413654976278079771569143599770012961608944169486855584840 > 6353422072225828488648158456028506016842739452267467678895252138 > 5225499546667278239864565961163548862305774564980355936345681743 > 2411251507606947945109659609402522887971089314566913686722874894 > 0560101503308617928680920874760917824938589009714909675985261365 > 5497818931297848216829989487226588048575640142704775551323796414 > 5152374623436454285844479526586782105114135473573952311342716610 > 2135969536231442952484937187110145765403590279934403742007310578 > 5390621983874478084784896833214457138687519435064302184531910484 > 8100537061468067491927819119793995206141966342875444064374512371 > 8192179998391015919561814675142691239748940907186494231961567945 > 2080951465502252316038819301420937621378559566389377870830390697 > 9207734672218256259966150142150306803844773454920260541466592520 > 1497442850732518666002132434088190710486331734649651453905796268 > 5610055081066587969981635747363840525714591028970641401109712062 > 8043903975951567715770042033786993600723055876317635942187312514 > 7120532928191826186125867321579198414848829164470609575270695722 > 0917567116722910981690915280173506712748583222871835209353965725 > 1210835791513698820914442100675103346711031412671113699086585163 > 9831501970165151168517143765761835155650884909989859982387345528 > 3316355076479185358932261854896321329330898570642046752590709154 > 8141654985946163718027098199430992448895757128289059232332609729 > 9712084433573265489382391193259746366730583604142813883032038249 > 0375898524374417029132765618093773444030707469211201913020330380 > 1976211011004492932151608424448596376698389522868478312355265821 > 3144957685726243344189303968642624341077322697802807318915441101 > 0446823252716201052652272111660396665573092547110557853763466820 > 6531
Re: Restarting a program
On May 22, 1:38 pm, Geoldr <[EMAIL PROTECTED]> wrote: > On May 22, 10:07 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > > > > > On May 22, 10:59 am, Geoldr <[EMAIL PROTECTED]> wrote: > > > > Hello all, I have written a simple program, and at the end of it, > > > instead of it closing I would like it to restart from the beggining. > > > Is there a way to do this? Put my code into a class function, or > > > something? > > > I guess I could do a while loop, but I think if there is a way to run > > > my code if it's in a class would be an easier option. I can't seem to > > > find many guides online but maybe I have not been looking in the right > > > places. > > > > Anybody have any ideas? > > > Putting your code in a function or class is probably the way to go. > > When I was doing C++, we'd just use a while loop for simple stuff, > > though. > > > It really shouldn't be all that hard to tell the code to call up the > > beginning of the program again. > > > Mike > > That's what I am trying to figure out, but it doesn't seem to work. Do > you have any example code of classes/functions that work for you? No...but I through some concept code together that does the basics: def repeater(): for i in range(10): print i def main(): ret = 'Y' while 1: if ret.upper() == 'Y': repeater() else: print 'Program finished...goodbye!' break ret = raw_input('Do you want to continue? (Y/N)') if __name__ == '__main__': main() I found that using the while was the easiest to create on short notice. You could probably do it with recursion too, but I'm not especially good at that. Another idea is to have some kind of sentinel value that both functions can access and use it somehow to tell whether or not to repeat. Hope that helps you get going. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is math.pi slightly wrong?
On May 22, 11:32 am, "Dutton, Sam" <[EMAIL PROTECTED]> wrote: > I've noticed that the value of math.pi -- just entering it at the interactive > prompt -- is returned as 3.1415926535897931, whereas (as every pi-obsessive > knows) the value is 3.1415926535897932... (Note the 2 at the end.) > > Is this a precision issue, or from the underlying C, or something else? How > is math.pi calculated? If you actually need that many digits, use a different library. >>> import gmpy >>> print gmpy.pi(64) # 64 bit precision 3.14159265358979323846 >>> print gmpy.pi(128) # 128 bit precision 3.141592653589793238462643383279502884197 >>> print gmpy.pi(16384) # 16384 bit precision 3.14159265358979323846264338327950288419716939937510582097494459 2307816406286208998628034825342117067982148086513282306647093844 6095505822317253594081284811174502841027019385211055596446229489 5493038196442881097566593344612847564823378678316527120190914564 8566923460348610454326648213393607260249141273724587006606315588 1748815209209628292540917153643678925903600113305305488204665213 8414695194151160943305727036575959195309218611738193261179310511 8548074462379962749567351885752724891227938183011949129833673362 4406566430860213949463952247371907021798609437027705392171762931 7675238467481846766940513200056812714526356082778577134275778960 9173637178721468440901224953430146549585371050792279689258923542 019956112129021960864034418159813629774771309960518707211349 9837297804995105973173281609631859502445945534690830264252230825 3344685035261931188171010003137838752886587533208381420617177669 1473035982534904287554687311595628638823537875937519577818577805 3217122680661300192787661119590921642019893809525720106548586327 8865936153381827968230301952035301852968995773622599413891249721 7752834791315155748572424541506959508295331168617278558890750983 8175463746493931925506040092770167113900984882401285836160356370 7660104710181942955596198946767837449448255379774726847104047534 6462080466842590694912933136770289891521047521620569660240580381 5019351125338243003558764024749647326391419927260426992279678235 4781636009341721641219924586315030286182974555706749838505494588 5869269956909272107975093029553211653449872027559602364806654991 198818347977535663698074265425278625518184175746728909279380 0081647060016145249192173217214772350141441973568548161361157352 5521334757418494684385233239073941433345477624168625189835694855 6209921922218427255025425688767179049460165346680498862723279178 6085784383827967976681454100953883786360950680064225125205117392 9848960841284886269456042419652850222106611863067442786220391949 4504712371378696095636437191728746776465757396241389086583264599 5813390478027590099465764078951269468398352595709825822620522489 4077267194782684826014769909026401363944374553050682034962524517 4939965143142980919065925093722169646151570985838741059788595977 2975498930161753928468138268683868942774155991855925245953959431 0499725246808459872736446958486538367362226260991246080512438843 9045124413654976278079771569143599770012961608944169486855584840 6353422072225828488648158456028506016842739452267467678895252138 5225499546667278239864565961163548862305774564980355936345681743 2411251507606947945109659609402522887971089314566913686722874894 0560101503308617928680920874760917824938589009714909675985261365 5497818931297848216829989487226588048575640142704775551323796414 5152374623436454285844479526586782105114135473573952311342716610 2135969536231442952484937187110145765403590279934403742007310578 5390621983874478084784896833214457138687519435064302184531910484 8100537061468067491927819119793995206141966342875444064374512371 8192179998391015919561814675142691239748940907186494231961567945 2080951465502252316038819301420937621378559566389377870830390697 9207734672218256259966150142150306803844773454920260541466592520 1497442850732518666002132434088190710486331734649651453905796268 5610055081066587969981635747363840525714591028970641401109712062 8043903975951567715770042033786993600723055876317635942187312514 7120532928191826186125867321579198414848829164470609575270695722 0917567116722910981690915280173506712748583222871835209353965725 1210835791513698820914442100675103346711031412671113699086585163 9831501970165151168517143765761835155650884909989859982387345528 3316355076479185358932261854896321329330898570642046752590709154 8141654985946163718027098199430992448895757128289059232332609729 9712084433573265489382391193259746366730583604142813883032038249 0375898524374417029132765618093773444030707469211201913020330380 1976211011004492932151608424448596376698389522868478312355265821 3144957685726243344189303968642624341077322697802807318915441101 0446823252716201052652272111660396665573092547110557853763466820 6531098965269186205647693125705863566201855810072936065987648611 7910453348850346113657686753249441668039626579787718556084552965 4126654085306143444318586769751456614068007002378776591344017127 494704205622305389945613140711270
Re: Python and Flaming Thunder
Mensanator wrote: > On May 22, 10:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >> Dave Parker <[EMAIL PROTECTED]> wrote: >> > But after getting input from children and teachers, etc, it started >> > feeling right. >> >> > For example, consider the two statements: >> >> > x = 8 >> > x = 10 >> >> > The reaction from most math teachers (and kids) was "one of those is >> > wrong because x can't equal 2 different things at the same time". >> >> This is a common feature in functional languages... >> >> Eg >> >> Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] >> [async-threads:0] [kernel-poll:false] >> >> Eshell V5.6.2 (abort with ^G) >> 1> X = 8. >> 8 >> 2> X = 10. >> ** exception error: no match of right hand side value 10 >> 3> >> >> That error message is the erlang interpreter saying "Hey I know X is >> 8, and you've said it is 10 - that can't be right", which is pretty >> much what math teachers say too... > > Are you saying that erlang treats 1> as an assignment, yet > treats 2> as a comparison? > > That's inconsistent. No wonder nobody uses erlang. In Prolog terms, they're both unification. If X has never been defined you can define it as 8 with no chance of contradicting anything. Once X is 8, the proposition "X is 10" is false. I act as though Erlang thinks the same. My Erlang chops aren't as good as my Prolog chops were. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On 22 mai, 18:14, cm_gui <[EMAIL PROTECTED]> wrote: > Python is slow. Oh, a troll... > Almost all of the web applications written in > Python are slow. Zope/Plone is slow, sloow, so very slooow. Even > Google Apps is not faster. Neither is Youtube. > Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster > than Python. > Okay, they probably use caching or some code compilation -- but Google > Apps and those Zope sites probably also use caching. > > I've yet to see a web application written in Python which is really > fast. Err, a very bad troll actually. Trop gros, passera pas. -- http://mail.python.org/mailman/listinfo/python-list
Re: Restarting a program
On May 22, 10:07 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On May 22, 10:59 am, Geoldr <[EMAIL PROTECTED]> wrote: > > > Hello all, I have written a simple program, and at the end of it, > > instead of it closing I would like it to restart from the beggining. > > Is there a way to do this? Put my code into a class function, or > > something? > > I guess I could do a while loop, but I think if there is a way to run > > my code if it's in a class would be an easier option. I can't seem to > > find many guides online but maybe I have not been looking in the right > > places. > > > Anybody have any ideas? > > Putting your code in a function or class is probably the way to go. > When I was doing C++, we'd just use a while loop for simple stuff, > though. > > It really shouldn't be all that hard to tell the code to call up the > beginning of the program again. > > Mike That's what I am trying to figure out, but it doesn't seem to work. Do you have any example code of classes/functions that work for you? -- http://mail.python.org/mailman/listinfo/python-list
2 different versions of python compiling files.
I am trying to upgrade from python 2.3 to 2.4 but not all machines can be upgraded. Can you guys tell me if this scenario is possible. 1. Any machine that uses .py files that use libraries that require 2.4 will have 2.4 on it. 2. rest of the machines will have 2.3 now there is a shared drive. lets say i write a new library called testlib.py and put it on the shared drive .. when a script uses it from a 2.4 based machine, it will generate a testlib.pyc and leave it on the shared drive. going forward that .pyc is used until the original lib is changed. now lets say a 2.3 based machine is trying to use that lib. it will try to use that pyc file which was compiled by py2.4. will it work or crash ? not sure if i did a good job on explaining my scenario. -- http://mail.python.org/mailman/listinfo/python-list