Is it possible to make a unittest decorator to rename a method from "x" to "testx?"

2013-08-07 Thread adam . preble
We were coming into Python's unittest module from backgrounds in nunit, where they use a decorate to identify tests. So I was hoping to avoid the convention of prepending "test" to the TestClass methods that are to be actually run. I'm sure this comes up all the time, but I mean not to have to

Re: beginner question (True False help)

2013-08-07 Thread wxjmfauth
Le mercredi 7 août 2013 10:17:21 UTC+2, eschne...@comcast.net a écrit : > I'm trying to create an option for the program to repeat if the user types > 'y' or 'yes', using true and false values, or otherwise end the program. If > anyone could explain to me how to get this code working, I'd appreci

Re: Reg secure python environment with web terminal emulator

2013-08-07 Thread dieter
"Lakshmipathi.G" writes: > Could you please share more info about creating raw binary executable > and its potential > problem. In an earlier message, you reported to have banned "gcc" to avoid "C" level exploits. A "raw binary executable" would allow the same exploits. Think of a binary generate

Re: [tkinter] trouble running imported modules in main program

2013-08-07 Thread David
On 8 August 2013 14:06, snakeinmyboot wrote: > > for REAL you guys...wtf does this even mean lol. what is a boilerplate test > code? Did you try at all to find the answer to this yourself? I ask because it took me only a few seconds to go to wikipedia and search for "boilerplate" find this for

Re: Mock pathc question

2013-08-07 Thread Avishay Balderman
Hi 1) I prefer to use start/stop and not the decorator . 2) mock_play is the name of the module where the code belongs Thanks Avishay Sent from my iPhone On 7 באוג 2013, at 21:01, Jean-Michel Pichavant wrote: - Mail original - Hi I would like to mock patch the attribute 'calc' in th

Re: Reg secure python environment with web terminal emulator

2013-08-07 Thread Lakshmipathi.G
> If you permit file I/O and anything that can spawn a process, it is > possible to create a raw binary executable and trigger its execution. > -- Yes,we permit file i/o with quota limits and spawning a process is allowed upto a limit. If I'm not wrong, we will be safe if user invokes sub

Re: [tkinter] trouble running imported modules in main program

2013-08-07 Thread snakeinmyboot
>if __name__ == '__main__': > root = tkinter.Tk() > app = MainClass(root) # 'MainClass' depends on the module. > root.mainloop > root.destroy for REAL you guys...wtf does this even mean lol. what is a boilerplate test code? -- http://mail.python.org/mailman/listinfo/python-list

Re: Crawl Quora

2013-08-07 Thread David Hutto
Never tried this, but if it's not data you're after, but a search term type of app, then ip address crawl, and if keyword/metadata, then crawl, and parse, just as it seems you are doing, for keywords, and url's associated with them, then eliminate url's without that specified keyword parameter into

Re: new to While statements

2013-08-07 Thread Larry Hudson
On 08/06/2013 08:38 PM, krismesenbr...@gmail.com wrote: import random def room (): hp = 10 while hp != 0: random_Number = random.randint(1, 2) #asking if you want to roll/play des = input("Would you like to roll the die?") One very trivial comment...

Re: outputting time in microseconds or milliseconds

2013-08-07 Thread matt . doolittle33
> > Taking a step back, you're probably better off using datetimes. You'll > > get all this conversion nonsense for free: > i did: from time import strftime, time from datetime import datetime now = datetime.now() self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) self.logf

Re: beginner question (True False help)

2013-08-07 Thread Larry Hudson
On 08/07/2013 01:17 AM, eschneide...@comcast.net wrote: I'm trying to create an option for the program to repeat if the user types 'y' or 'yes', using true and false values, or otherwise end the program. If anyone could explain to me how to get this code working, I'd appreciate it. letters='ab

Re: make elements of a list twice or more.

2013-08-07 Thread liuerfire Wang
On Thu, Aug 8, 2013 at 6:18 AM, Joshua Landau wrote: > > I'm actually posting to point out > http://www.python.org/dev/peps/pep-0448/ would let you write: > > [*(item, item) for item in items] It seems like that it can be only used in python 3.4? I just use python 2.7 because of work needs.

Re: new to While statements

2013-08-07 Thread Dave Angel
Vito De Tullio wrote: > Dan Sommers wrote: > while "asking for reponse": >>> while "adventuring": >>> >>> that's a funny way to say `while True:`... >> >> Funny, perhaps, the first time you see it, but way more informative than >> the other way to the next one who come

Re: beginner question (True False help)

2013-08-07 Thread Dave Angel
eschneide...@comcast.net wrote: > What I wanted to happen is when the user typed something other than 'y' or > 'yes' after being asked 'go again?', the batman==False line would cause the > program to stop asking anything and say 'this is the end'. Instead, what is > happening is that the progra

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Luca Cerone
Thanks for the help Peter! > > > > >> def make_instancemethod(inst, methodname): > > >> return getattr(inst, methodname) > > > > > > This is just getattr -- you can replace the two uses of > > > make_instancemethod with getattr and delete this ;). > > > > D'oh ;) -- http://mail.py

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Joshua Landau
On 7 August 2013 23:26, Luca Cerone wrote: > Thanks for the post. > I actually don't know exactly what can and can't be pickles.. I just try it and see what works ;). The general idea is that if it is module-level it can be pickled and if it is defined inside of something else it cannot. It depe

Re: make elements of a list twice or more.

2013-08-07 Thread Joshua Landau
On 7 August 2013 17:59, Peter Otten <__pete...@web.de> wrote: > liuerfire Wang wrote: > >> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are >> different type). Now I wanna generate a new list as [b, b, a, a, c, c]. >> >> I know we can do like that: >> >> tmp = [] >> for i

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Luca Cerone
Thanks for the post. I actually don't know exactly what can and can't be pickles.. not what partialing a function means.. Maybe can you link me to some resources? I still can't understand all the details in your code :) -- http://mail.python.org/mailman/listinfo/python-list

Re: beginner question (True False help)

2013-08-07 Thread eschneider92
What I wanted to happen is when the user typed something other than 'y' or 'yes' after being asked 'go again?', the batman==False line would cause the program to stop asking anything and say 'this is the end'. Instead, what is happening is that the program just keeps going. I figured that after

Re: Is a Metaclass the appropriate way to solve this problem?

2013-08-07 Thread Ian Kelly
On Wed, Aug 7, 2013 at 1:38 PM, Matthew Lefavor wrote: > I know that to create the DatabaseField objects I should be using a > descriptor. But I also want the DataSet to automatically gain methods that > will convert it into the expected JSON syntax (e.g., a __specifier__ method > that will create

Re: [tkinter] trouble running imported modules in main program

2013-08-07 Thread Cousin Stanley
Terry Reedy wrote: > Code comments : > > double and triple spacing code > make it painful to read, Not for everyone :-) I prefer mostly double-spaced code in any language > especially in a 10 line box. Agree, but the 10 line box would not be used for routin

Is a Metaclass the appropriate way to solve this problem?

2013-08-07 Thread Matthew Lefavor
All: Like most people, I find the whole metaclass topic pretty obscure, and I have avoided trying to use one for a while. I am also aware of Tim Peter's famous advice that if you have to ask whether you need a metaclass, then you almost certainly don't. But in this case I know I am solving a probl

Re: new to While statements

2013-08-07 Thread Vito De Tullio
Dan Sommers wrote: >>> while "asking for reponse": >> >>> while "adventuring": >> >> that's a funny way to say `while True:`... > > Funny, perhaps, the first time you see it, but way more informative than > the other way to the next one who comes along and reads it. While I und

Re: Mock pathc question

2013-08-07 Thread Jean-Michel Pichavant
- Mail original - > Hi > I would like to mock patch the attribute 'calc' in the 'Client' class > (See code below). > I have 2 unit tests: > 1) test1 - that patch an existing instance of 'Client' - it works > fine. > 1) test2 - that tries to patch the 'Client' class. My expectation is > th

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-07 Thread Ethan Furman
On 08/07/2013 02:24 AM, Shiyao Ma wrote: Sorry. I don't quite get it. As you said, it first tries, leftOperand.__eq__(rightOperand) then if it returns NotImplemented, it goes to invoke rightOperand.__eq__(leftOperand). But for any reason, [] == () returns false, why? A list that is empty is

Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-07 Thread Skip Montanaro
> I have one on my desk at work whose name I can't remember off the > top of my head. I still refer to it from time-to-time. If you'd > like a reference, let me know and I'll check on it at work. While I think of it: "The Practical SQL Handbook; Using Structured Query Language," by Bowman, Emer

Re: make elements of a list twice or more.

2013-08-07 Thread Peter Otten
liuerfire Wang wrote: > Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are > different type). Now I wanna generate a new list as [b, b, a, a, c, c]. > > I know we can do like that: > > tmp = [] > for i in x: > tmp.append(i) > tmp.append(i) > > However, I wander i

make elements of a list twice or more.

2013-08-07 Thread liuerfire Wang
Sorry for the title which didn't make clear. Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are different type). Now I wanna generate a new list as [b, b, a, a, c, c]. I know we can do like that: tmp = [] for i in x: tmp.append(i) tmp.append(i) However, I wander

Re: Creating a running tally/ definitely new to this

2013-08-07 Thread Joshua Landau
On 6 August 2013 16:24, wrote: > On Monday, August 5, 2013 10:15:30 PM UTC-4, Dave Angel wrote: >> gratedme...@gmail.com wrote: >> >> > I currently working on a game, where I need to maintain a running tally of >> > money, as the player makes purchases as they navigate thru game. I not >> > e

Re: make elements of a list twice or more.

2013-08-07 Thread liuerfire Wang
I got it! It can do like [i for i in x for y in range(2)] On Wed, Aug 7, 2013 at 4:50 PM, liuerfire Wang wrote: > Sorry for the title which didn't make clear. > > Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are > different type). Now I wanna generate a new list as [b,

Re: HTTP post with urllib2

2013-08-07 Thread cerr
On Tuesday, August 6, 2013 5:14:48 PM UTC-7, MRAB wrote: > On 06/08/2013 23:52, cerr wrote: > > > Hi, > > > > > > Why does this code: > > > > > > #!/usr/bin/python > > > > > > > > > import urllib2 > > > from binascii import hexlify, unhexlify > > > > > > host = "localhost" > > > uri="/t

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Peter Otten
Joshua Landau wrote: > On 7 August 2013 15:46, Peter Otten <__pete...@web.de> wrote: >> def make_instancemethod(inst, methodname): >> return getattr(inst, methodname) > > This is just getattr -- you can replace the two uses of > make_instancemethod with getattr and delete this ;). D'oh ;)

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Joshua Landau
On 7 August 2013 15:46, Peter Otten <__pete...@web.de> wrote: > import copy_reg > import multiprocessing > import new "new" is deprecated from 2.6+; use types.MethodType instead of new.instancemethod. > def make_instancemethod(inst, methodname): > return getattr(inst, methodname) This is jus

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Peter Otten
Joshua Landau wrote: > On 7 August 2013 11:10, Luca Cerone wrote: >> I can't try it now, I'll let you know later if it works! >> (Though just by reading I can't really understand what the code does). > > Well, > >>> from multiprocessing import Pool >>> from functools import partial >>> >>> clas

Mock pathc question

2013-08-07 Thread balderman
Hi I would like to mock patch the attribute 'calc' in the 'Client' class (See code below). I have 2 unit tests: 1) test1 - that patch an existing instance of 'Client' - it works fine. 1) test2 - that tries to patch the 'Client' class. My expectation is that after the patching, every instance of

Re: Enum vs OrderedEnum

2013-08-07 Thread Neil Cerutti
On 2013-08-07, Ian Kelly wrote: > On Tue, Aug 6, 2013 at 7:55 PM, Ben Finney wrote: >> Ian Kelly writes: >> Terrain that is ?radiated? would be terrain that has some kind of spokes >> spreading out from its centre. I think you mean ?irradiated?. >> >> Hope the game goes well :-) > > It's actuall

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Joshua Landau
On 7 August 2013 11:10, Luca Cerone wrote: > I can't try it now, I'll let you know later if it works! > (Though just by reading I can't really understand what the code does). Well, >> from multiprocessing import Pool >> from functools import partial >> >> class A(object): >> def __init__(sel

Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-07 Thread Skip Montanaro
> Can someone suggest me better resources for learning sql/sqlite3? The concepts behind the Structured Query Language haven't changed much since Edgar Codd first developed them in the 1970s. (He received the Turing Award in 1981 for this work.) Building and querying databases is very easy to do

Re: lxml tostring quoting too much

2013-08-07 Thread andrea crotti
2013/8/6 Chris Down : > On 2013-08-06 18:38, andrea crotti wrote: >> I would really like to do the following: >> >> from lxml import etree as ET >> from lxml.builder import E >> >> url = "http://something?x=10&y=20"; >> l = E.link(url) >> ET.tostring(l) -> "http://something?x=10&y=20" >> >> However

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Luca Cerone
> > doesn't work neither in Python 2.7, nor 3.2 (by the way I can't use Python > > 3 for my application). > > Are you using Windows? Over here on 3.3 on Linux it does. Not on 2.7 though. No I am using Ubuntu (12.04, 64 bit).. maybe things changed from 3.2 to 3.3? > from multiprocessing import

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Joshua Landau
On 7 August 2013 09:33, Luca Cerone wrote: > To correct my example: > > from multiprocessing import Pool > > class A(object): > def __init__(self,x): > self.value = x > def fun(self,x): > return self.value**x > > l = range(100) > p = Pool(4) > op = p.map(A(3).fun, l) > > do

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-07 Thread Chris Angelico
On Wed, Aug 7, 2013 at 10:24 AM, Shiyao Ma wrote: > Sorry. I don't quite get it. As you said, it first tries, > leftOperand.__eq__(rightOperand) then if it returns NotImplemented, it goes > to invoke rightOperand.__eq__(leftOperand). But for any reason, [] == () > returns false, why? If neither o

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-07 Thread Shiyao Ma
Sorry. I don't quite get it. As you said, it first tries, leftOperand.__eq__(rightOperand) then if it returns NotImplemented, it goes to invoke rightOperand.__eq__(leftOperand). But for any reason, [] == () returns false, why? On Mon, Aug 5, 2013 at 7:06 AM, Chris Angelico wrote: > On Sun, Aug

Re: Reg secure python environment with web terminal emulator

2013-08-07 Thread Lakshmipathi.G
Hi - Thanks for the response. Yes, we used OS features to restrict the system user accounts. We don't allow gcc - this helped us to avoid kernel exploits via C code like : https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=42827&forum=59 https://bugzilla.redhat.com/show_bu

Resuming the HTTP Download of a File and HTTP compression

2013-08-07 Thread iMath
the file I want to download is 100 bytes uncompressed, the downloads was interrupted when 5000 bytes compressed data was transmitted .If I want to Resuming the HTTP Download ,I wonder what value of the HTTP Range header should be ,“bytes=5000-“ or “bytes= -”? why ? -- http://mail.python.org

Resuming the HTTP Download of a File and HTTP compression

2013-08-07 Thread iMath
the file I want to download is 100 bytes uncompressed, the downloads was interrupted when 5000 bytes compressed data was transmitted .If I want to Resuming the HTTP Download ,I wonder what value of the HTTP Range header should be ,“bytes=5000-“ or “bytes= -”? why ? -- http://mail.python.org

Re: beginner question (True False help)

2013-08-07 Thread Joshua Landau
On 7 August 2013 09:17, wrote: > I'm trying to create an option for the program to repeat if the user types > 'y' or 'yes', using true and false values, or otherwise end the program. If > anyone could explain to me how to get this code working, I'd appreciate it. Always tell people what in par

Re: Using Pool map with a method of a class and a list

2013-08-07 Thread Luca Cerone
Hi Joshua thanks! > I think you might not understand what Chris said. > Currently this does *not* work with Python 2.7 as you suggested it would. > >>> op = map(A.fun,l) Yeah actually that wouldn't work even in Python 3, since value attribute used by fun has not been set. It was my mistake in th

beginner question (True False help)

2013-08-07 Thread eschneider92
I'm trying to create an option for the program to repeat if the user types 'y' or 'yes', using true and false values, or otherwise end the program. If anyone could explain to me how to get this code working, I'd appreciate it. letters='abcdefghijklmn' batman=True def thingy(): print('type le

Re: Enum vs OrderedEnum

2013-08-07 Thread Ian Kelly
On Tue, Aug 6, 2013 at 6:33 PM, Ethan Furman wrote: > class Environment(AutoNumber): > > gaia = 2.0 > fertile = 1.5 > terran = 1.0 > jungle = 1.0 > ocean = 1.0 > arid = 1.0 > steppe = 1.0 > desert = 1.0 > minimal = 1.0 > barren = 0.5 > tundra = 0.5 >

Re: Working with XML/XSD

2013-08-07 Thread David Barroso
I will start looking to the links and libraries you pointed out. As the schema definitions are provided by the vendor I think I will go for PyXB. Thanks! On Wed, Aug 7, 2013 at 8:00 AM, dieter wrote: > David Barroso writes: > > > I was wondering if someone could point me in the right directio

Re: pexpect, loading an entry field

2013-08-07 Thread Lakshmipathi.G
Hi - I'm using Python 2.7.3 (Fedora 17) . I tried a simple example with pexpect to copy a file to remote system. It works $ cat pex.py import pexpect s = pexpect.spawn ('scp pex.py root@10.30.77.244:/tmp') s.expect ('Password:') s.sendline ('a') s.expect(pexpect.EOF,timeout=20) Execute above prog

Re: Enum vs OrderedEnum

2013-08-07 Thread Ian Kelly
On Tue, Aug 6, 2013 at 7:55 PM, Ben Finney wrote: > Ian Kelly writes: > Terrain that is “radiated” would be terrain that has some kind of spokes > spreading out from its centre. I think you mean “irradiated”. > > Hope the game goes well :-) It's actually a reimplementation of a game from 1993, s