Re: checking if a list is empty

2011-05-13 Thread Chris Rebert
On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > The boolean domain is only a 100 years old. > Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of has an explicit boolean datatype. Heck, as of C99, even C has one now. I conjecture

Re: I don't understand generator.send()

2011-05-14 Thread Chris Rebert
On Sat, May 14, 2011 at 5:08 PM, Victor Eijkhout wrote: > #! /usr/bin/env python > > def ints(): >    i=0 >    while True: >        yield i >        i += 1 > > gen = ints() > while True: >    i = gen.next() >    print i >    if i==5: >        r = gen.send(2) >        print "return:",r >    if i>10

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: > Dear python experts, > > I use a huge python dictionary where the values are lists of that > dictionary's keys (yes, a graph).  Each key is thus referenced several > times. > > As the keys are rather large objects, I would like to save memo

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 1:53 PM, Terry Reedy wrote: > On 5/15/2011 6:46 AM, Christoph Groth wrote: >> But hey, they keys of my dictionary are actually strings, so I can use >> the built-in intern.  Somehow, I have never stumbled accross this >> built-in function so far. > > It was, however, remov

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 8:53 PM, Gnarlodious wrote: > Can someone please explain what I am doing wrong? > > Calling script: > > from Gnomon import GnomonBase > Gnomon=GnomonBase(3) > > > Called script: > > class GnomonBase(object): >    def __init__(self, bench): >        # do stuff > > But all I

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 9:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. > > My problem is that in order to run mod_wsgi I had to downgrade to > Python 3.1.3 whic

Re: indirect assignment question

2011-05-16 Thread Chris Rebert
On Mon, May 16, 2011 at 10:13 PM, Andy Baxter wrote: > Hi, > > I have some lines of code which currently look like this: > >      self.window = self.wTree.get_widget("mainWindow") >      self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") >      self.outputToggleButton = self.wTree

Re: if statement on lenght of a list

2011-05-17 Thread Chris Rebert
On Tue, May 17, 2011 at 11:02 AM, Joe Leonardo wrote: > > Hey all, > > Totally baffled by this…maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > def breakLine(value): >     if value.__class__() != [] and value.__len__() != 19: >     print 'You

Re: hash values and equality

2011-05-19 Thread Chris Rebert
On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: > Several folk have said that objects that compare equal must hash equal, and > the docs also state this > http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > I'm hoping somebody can tell me what horrible thing will happen i

Re: hash values and equality

2011-05-20 Thread Chris Rebert
On Fri, May 20, 2011 at 10:56 AM, Ethan Furman wrote: > Chris Rebert wrote: >> On Thu, May 19, 2011 at 10:43 PM, Ethan Furman wrote: >>> Several folk have said that objects that compare equal must hash equal, >>> and >>> the docs also state this >

Re: Problem in using subprocess module and communicate()

2011-05-21 Thread Chris Rebert
On Sat, May 21, 2011 at 8:56 AM, vijay swaminathan wrote: > Hi  Gurus, > > I'm having some problem in using the communicate() along with the > subprocess.I would like to invoke a command prompt and pass  on a .bat file > to execute. I went through the subprocess module and understood that using >

Re: count strangeness

2011-05-21 Thread Chris Rebert
On Sat, May 21, 2011 at 11:02 PM, James Stroud wrote: > tal 65% python2.7 > Python 2.7.1 (r271:86832, May 21 2011, 22:52:14) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > py> class C(object): > ...   def __init__(

Re: Is there a better way to solve this?

2011-05-21 Thread Chris Rebert
On Sat, May 21, 2011 at 11:28 PM, Ganapathy Subramanium wrote: > Hello, > > I'm a new bie to python programming and on the processing of learning python > programming. I have coded my first program of fibonnaci generation and would > like to know if there are better ways of achieving the same. > >

Re: count strangeness

2011-05-22 Thread Chris Rebert
On Sat, May 21, 2011 at 11:32 PM, James Stroud wrote: > Chris Rebert wrote: >>> >>> WTF? >> >> Assuming your question is "Why is 1024 there twice?", the answer is > > The question is "Why is 1024 there at all?" It should be 10. Ah.

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

2011-05-24 Thread Chris Rebert
On Tue, May 24, 2011 at 1:31 AM, Cathy James wrote: > dear mentor, > > I need help with my code: In addition to what others have already said... > please see my attempt below and help: > > #1) open file and display current file contents: > f = open ('c:/testing.txt'', 'r') > f.readlines() > #2)

Re: Puzzled by list-appending behavior

2011-05-25 Thread Chris Rebert
On Wed, May 25, 2011 at 9:46 PM, Uncle Ben wrote: > In playing with lists of lists, I found the following: > > (In 3.1, but the same happens also in 2.7) > > list = [1,2,3] > list.append ( [4,5,6] ) Note the lack of output after this line. This indicates that list.append([4,5,6]) returned None. C

Re: Puzzled by list-appending behavior

2011-05-26 Thread Chris Rebert
On Thu, May 26, 2011 at 12:23 AM, Chris Angelico wrote: > On Thu, May 26, 2011 at 5:20 PM, Chris Angelico wrote: >> >> Ben Finney has already answered the main question > > Giving credit where credit's due, it was more Chris Rebert's post that > answered the question. Sorry Chris! Eh, one can't

Re: scope of function parameters

2011-05-29 Thread Chris Rebert
On Sun, May 29, 2011 at 1:30 AM, Henry Olders wrote: > I just spent a considerable amount of time and effort debugging a program. > The made-up code snippet below illustrates the problem I encountered: > > def main(): >        a = ['a list','with','three elements'] >        print a >        print

Re: How to catch a line with Popen

2011-05-29 Thread Chris Rebert
On Sun, May 29, 2011 at 3:02 AM, TheSaint wrote: > Tim Roberts wrote: > >> Are you specifying a buffer size in the Popen command?  If not, then the >> Python side of things is unbuffered > > The buffer is as per default. The program reports one line around 1/2 second > time. > I think I'll look in

Re: scope of function parameters

2011-05-29 Thread Chris Rebert
On Sun, May 29, 2011 at 10:53 AM, Chris Angelico wrote: > On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano > wrote: >> If a name is assigned to anywhere in the function, treat it as a local, >> and look it up in the local namespace. If not found, raise >> UnboundLocalError. >> > > Wait wha? I've

Re: scope of function parameters

2011-05-30 Thread Chris Rebert
On Mon, May 30, 2011 at 12:12 AM, Laurent Claessens wrote: > Le 29/05/2011 23:42, Ben Finney a écrit : >> Peter Pearson  writes: >> >>>  Python works in terms of objects having names, and one >>>  object can have many names. >> >> Or no names. So it's less accurate (though better than talking of >

Re: Best way to compute length of arbitrary dimension vector?

2011-05-30 Thread Chris Rebert
On Mon, May 30, 2011 at 2:11 AM, Gabriel wrote: > Well, the subject says it almost all: I'd like to write a small Vector > class for arbitrary-dimensional vectors. > > I am wondering what would be the most efficient and/or most elegant > way to compute the length of such a Vector? > > Right now, I

Re: scope of function parameters (take two)

2011-05-30 Thread Chris Rebert
On Mon, May 30, 2011 at 11:37 PM, Henry Olders wrote: > On 2011-05-31, at 1:13 , Wolfgang Rohdewald wrote: >> >> what you really seem to want is that a function by default >> cannot have any side effects (you have a side effect if a >> function changes things outside of its local scope). But >> th

Re: Something is rotten in Denmark...

2011-05-31 Thread Chris Rebert
On Mon, May 30, 2011 at 11:48 PM, harrismh777 wrote: fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] > > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]         <=== not good > >    ( that was a big surprise! . . . ) >     lambda?  closure?  scope?   bug? >

Re: BadValueError: Property title is required

2011-05-31 Thread Chris Rebert
On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > Hello, > > I'm trying to create simple method to create category. I set the model > category: > > class Category(db.Model): >  title = db.StringProperty(required=True) >  clashes_count = db.IntegerProperty(default=0) > The problem is that I'm

Re: Updated now can't scroll uparrow

2011-06-01 Thread Chris Rebert
On Wed, Jun 1, 2011 at 7:37 AM, Gnarlodious wrote: > I updated Python to 3.1.3 on Mac OSX. Now suddenly in the Interactive > interpreter I get all this instead of scrolling the history: > ^[[A^[[A^[[A > > What's wrong and how to fix it? Looks like GNU readline support wasn't enabled in the b

Re: how to avoid leading white spaces

2011-06-01 Thread Chris Rebert
On Wed, Jun 1, 2011 at 12:31 AM, rakesh kumar wrote: > > Hi > > i have a file which contains data > > //ACCDJ EXEC DB2UNLDC,DFLID=&DFLID,PARMLIB=&PARMLIB, > // UNLDSYST=&UNLDSYST,DATABAS=MBQV1D0A,TABLE='ACCDJ   ' > //ACCT  EXEC DB2UNLDC,DFLID=&DFLID,PARMLIB=&PARMLIB, >

Re: Urgent - Would like to see output of each block of python

2016-06-06 Thread Chris Rebert
On Sun, Jun 5, 2016 at 11:57 PM, Archana Sonavane wrote: > Hi Team, > > I don't have any idea about python scripts, i have ganglia tool python > scripts. > > I would like see the output of each code block, could you please guide. > > The code as follows: With regard to your Subject line, please

Re: a Python Static Analyzer

2013-12-14 Thread Chris Rebert
On Sat, Dec 14, 2013 at 5:31 PM, Dan Stromberg wrote: > Where does PySonar2 sit in the spectrum from pylint > (thorough/pedantic) to pyflakes (relaxed/few-false-positives)? > > I use pylint and pyflakes a lot, and I've heard that PyChecker sits in > between them on this axis. My impression is tha

Re: Postfix conditionals

2014-01-05 Thread Chris Rebert
On Sun, Jan 5, 2014 at 12:24 PM, Göktuğ Kayaalp wrote: > Hi, > > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a > statement, which determines whether the statement runs or not: > > py> for i in [False]: > ... break if not i > > The above piece of c

Re: Re: Postfix conditionals

2014-01-05 Thread Chris Rebert
on that I have posted > to python-list@python.org, so I am forwarding it to here. > Original Message > Subject: Re: Postfix conditionals > Date: Sun, 5 Jan 2014 14:09:14 -0800 > From: Chris Rebert > To: Göktuğ Kayaalp > CC: Python -- https://mail.pyth

Re: UTC "timezone" causing brain explosions

2014-01-29 Thread Chris Rebert
On Wed, Jan 29, 2014 at 1:52 PM, Skip Montanaro wrote: > Following up on my earlier note about UTC v. GMT, I am having some > trouble grokking attempts to convert a datetime into UTC. Consider > these three values: > import pytz UTC = pytz.timezone("UTC") LOCAL_TZ = pytz.timezone("A

Re: python domain in China. This showed up on Python list

2015-12-01 Thread Chris Rebert
On Tue, Dec 1, 2015 at 2:10 AM, Laura Creighton wrote: > I think we have just dodged a bullet, let us now go thank the > nice people who sent us this and figure out how we should > secure the domain. > > Laura > > > --- Forwarded Message > > Return-Path: > Date: Tue, 1 Dec 2015 15:12:58 +0800

Re: Decimals and other numbers

2015-01-08 Thread Chris Rebert
On Thu, Jan 8, 2015 at 6:33 PM, Devin Jeanpierre wrote: > I noticed some very PHP-ish behavior today: > import decimal x = 0 y = float(x) z = decimal.Decimal(x) x == y == z == x > True x ** x > 1 y**y > 1.0 z**z > Traceback (most recent call last): > File

Re: Language design

2013-09-10 Thread Chris Rebert
* No explicit variable declarations (modulo `global`+`nonlocal`) means that variable name typos can't be reliably detected at compile-time. * The value of the loop variable at call-time for functions defined within a loop trips people up. * No self-balancing tree datatype of any kind is included in

Re: I am never going to complain about Python again

2013-10-09 Thread Chris Rebert
On Wed, Oct 9, 2013 at 9:36 PM, Steven D'Aprano wrote: > Just came across this little Javascript gem: > > ",,," == Array((null,'cool',false,NaN,4)); > > => evaluates as true > > http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array > > I swear, I am never going to complain about Python a

Re: How to parse JSON passed on the command line?

2013-11-06 Thread Chris Rebert
On Wed, Nov 6, 2013 at 7:53 PM, Anthony Papillion wrote: > Hello Everyone, > > I'm writing a little helper script in Python that will access a JSON > formatted argument from the shell when it's called. The parameter will > look like this: > > {"url":"http://www.google.com"} > > So, if my program i

Re: looking for standard/builtin dict-like data object

2015-08-10 Thread Chris Rebert
On Mon, Aug 10, 2015 at 8:22 PM, Vladimir Ignatov wrote: > Hi, > > In my code I often use my own home-brewed object for passing bunch of > data between functions. Something like: > > class Data(object): > def __init__ (self, **kwargs): > self.__dict__ = kwargs > > > > return Data(

Re: Python/Github

2015-08-24 Thread Chris Rebert
On Mon, Aug 24, 2015 at 1:14 PM, DBS wrote: > Hello, > > I'm trying to retrieve the number of commits and changed files on all pull > requests submitted to a branch. > > The call to get all the pull requests is GET /repos/:owner/:repo/pulls, but > it does not return "commits" or "changed_files".

Re: more itertools

2015-08-31 Thread Chris Rebert
On Mon, Aug 31, 2015 at 6:42 PM, Mark Lawrence wrote: > This contained the itertool recipes and was available on pypi but looks like > it's gone. Can anybody tell me if it's defunct, superseded or what? What do you mean? It's still there AFAICT: https://pypi.python.org/pypi/more-itertools St

Re: Distributing python applications as a zip file

2014-07-22 Thread Chris Rebert
On Tue, Jul 22, 2014 at 9:23 PM, Steven D'Aprano wrote: > A little known feature of Python: you can wrap your Python application in > a zip file and distribute it as a single file. The trick to make it > runnable is to put your main function inside a file called __main__.py > inside the zip file.

Re: Linux distros w/o Python in "base" installation

2014-08-11 Thread Chris Rebert
On Mon, Aug 11, 2014 at 11:53 AM, Grant Edwards wrote: > I just installed Arch Linux for the first time, and was surprosed to > find that Python isn't installed as part of a "base" system. It's > also not included in the 'base-devel' package group. It's trivial to > install, but I'd still pretty

Re: Import Doesn't Import

2014-10-15 Thread Chris Rebert
On Wednesday, October 15, 2014, ryguy7272 wrote: > So sorry everyone. I've posted here several times today. This is VERY > frustrating. > > So, I'm reading this link. > https://docs.python.org/2/howto/urllib2.html > > Important note!: The "/2/" in the URL means those docs are for Python 2.x Wh

Re: Best way to check that you are at the beginning (the end) of an iterable?

2011-09-07 Thread Chris Rebert
On Wed, Sep 7, 2011 at 5:24 PM, Miki Tebeka wrote: > I guess enumerate is the best way to check for first argument. Note that if > someone passes you the iterator as argument you have now way of checking if > the consumed items from it. > > istail can be implemented using itertools.chain, see >

Re: Applying a function recursively

2011-09-10 Thread Chris Rebert
On Sat, Sep 10, 2011 at 12:19 AM, hetchkay wrote: > Hi, > I want to apply a "convert" function on an object as follows: > If the object is of MyType type, invoke the passed in function. > If the object is a dictionary, apply on the keys and values of the > dictionary recursively. > If the object i

Re: recursive algorithm for balls in numbered boxes

2011-09-10 Thread Chris Rebert
On Sat, Sep 10, 2011 at 5:43 PM, Dr. Phillip M. Feldman wrote: > I've written a recursive class that creates an iterator to solve a general > formulation of the combinatorics problem known as "balls in numbered boxes" > (also known as "indistinguishable balls in distinguishable boxes").  The > cod

Re: convert time

2011-09-10 Thread Chris Rebert
2011/9/10 守株待兔 <1248283...@qq.com>: > how can i convert "Dec 11" into  2011-12? Read the fine manuals for the `time` or `datetime` modules. http://docs.python.org/library/datetime.html >>> from datetime import datetime >>> datetime.strptime("Dec 11", "%b %y") datetime.datetime(2011, 12, 1, 0, 0)

Re: What do you guys think about adding a method "to_json"

2011-09-11 Thread Chris Rebert
2011/9/11 Juan Pablo Romero Méndez : > Hello, > > What do you guys think about adding a method "to_json" to dictionaries > and sequence types? Perhaps through a module import? Why? We already have json.dumps(); seems to cover the use case. Cheers, Chris -- http://mail.python.org/mailman/listinfo

Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson wrote: > I have written a class that uses ftplib.FTP as the parent. > I need to reconcile the modified time of a workstation file with > that same filename on a remote server. > Let's say we have a file called '400.shtml'. I get the mtime on > my works

Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve wrote: > Hi, > I have a small program where I want to do just a small regex operation. > I want to see if value of a variable 'A' is present in an another variable > 'B'.  The below code works fine but as soon as the variable 'A' has some > string includ

Re: Problem with Dos command by python script

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 1:13 PM, Jonatas Emidio wrote: > Here i come!! > > I have the following problem... > I need run by python script a string with some "DOS commands - Windows > prompt"!! > For exemple: > print 'cd temp' > print 'mkdir temp_app' > > How can i run this string in the python, but

Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve wrote: > If A in B: > does nt seem to be working. > Am I missing something here. Please provide a snippet of the code in question, and be specific about how it's not working. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listi

Re: cause __init__ to return a different class?

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 10:20 PM, Matthew Pounsett wrote: > I'm wondering if there's a way in python to cause __init__ to return a class > other than the one initially specified.  My use case is that I'd like to have > a superclass that's capable of generating an instance of a random subclass.

Re: method:wrong structure

2011-09-15 Thread Chris Rebert
2011/9/15 守株待兔 <1248283...@qq.com>: > there are  three  programs,all of them  left  main  structure, > code0 is ok,i don't know why code2 and code3 can't run,how to fix them? > code0 > class   webdata(object): >     def  __init__(self,arg): > >     def  loadequity(self): > >     def  loadoption(sel

Re: Killing threads (was Re: Cancel or timeout a long running regular expression)

2011-09-17 Thread Chris Rebert
On Sat, Sep 17, 2011 at 2:35 PM, Chris Angelico wrote: > On Sun, Sep 18, 2011 at 5:00 AM, Nobody wrote: >> The only robust solution is to use a separate process (threads won't >> suffice, as they don't have a .kill() method). > > Forking a thread to discuss threads ahem. > > Why is it that th

Re: Re: Where can I find a lexical spec of python?

2011-09-21 Thread Chris Rebert
On Wed, Sep 21, 2011 at 9:33 AM, 程劭非 wrote: > Thanks Thomas. > I've read the document > http://docs.python.org/py3k/reference/lexical_analysis.html > > but I worried it might leak some language features like "tab magic". > > For I'm working on a parser with JavaScript I need a more strictly defin

Re: Python deadlock using subprocess.popen and communicate

2011-09-21 Thread Chris Rebert
On Wed, Sep 21, 2011 at 8:09 PM, Atherun wrote: > This is on windows with python 2.6. > I can't seem to remove a possibility of a  deadlock in one of my > scripts at the moment.  Its not a constant deadlock but it appears > from time to time.  The code is below: > > try: > >        process = > sub

Re: Python deadlock using subprocess.popen and communicate

2011-09-21 Thread Chris Rebert
On Wed, Sep 21, 2011 at 8:32 PM, Roy Smith wrote: > My reading of the docs > (http://docs.python.org/release/2.6.7/library/subprocess.html#popen-objec > ts) says that Popen.poll() doesn't return a value, it sets the object's > return code attribute, which you can then interrogate. Popen.poll():

Re: Why is the shutil module called shutil?

2011-09-23 Thread Chris Rebert
On Fri, Sep 23, 2011 at 8:36 PM, Fletcher Johnson wrote: > The topic says it all: > Why is shutil named shutil? What does it stand for? This is just a > mild curiosity of mine. "sh" is short for "shell", in line with Unix convention, where the default shell is located at /bin/sh. http://en.wikipe

Re: multinomial combinations

2011-09-24 Thread Chris Rebert
On Sat, Sep 24, 2011 at 12:06 AM, Dr. Phillip M. Feldman wrote: > > I wrote a small generator function that produces multinomial combinations. > (Python's itertools module does ordinary combinations, but not multinomial > combinations).  The code essentially works, except that the the last > combi

Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Chris Rebert
On Mon, Sep 26, 2011 at 1:55 AM, Gelonida N wrote: > Hi, > > So far I used optparse.OptionParser for parsing command line arguments > for my python scripts. So far I was happy, with a one level approach, > where I get only one help text > > Now I'd like to create a slightly different python script

Re: QA Engineering/ Python/ Contract/ Austin, TX

2011-09-26 Thread Chris Rebert
On Mon, Sep 26, 2011 at 1:56 PM, TOM wrote: > Tom Gugger > Independent Recruiter > tgug...@bex.net > > US Citizens or Greencard > On Site > > > QA Engineering/ Python/ Contract/ Austin, TX > > This is an immediate start, such as next week. I need three > contractors Such postings belong on the Py

Re: Error 'No module named _sha256' when importing random in python 2.7.1

2011-09-27 Thread Chris Rebert
On Tue, Sep 27, 2011 at 2:28 AM, Wong Wah Meng-R32813 wrote: > I just built python 2.7.1 on my HP Itanium 64-bit platform, using aCC. I > encountered following issue when importing the random module. Does anyone > know why am I getting this error? Thanks in advance for your reply. >  File "hash

Re: Multiplication error in python

2011-09-27 Thread Chris Rebert
On Tue, Sep 27, 2011 at 10:21 AM, sakthi wrote: > In the following code, l=[1,2,3,4,5] i=0 for a in l: > ...     p=2*a > ...     t=p+i > ...     i=t > ... t > 45 > > Python gives an answer as 45. But i am getting 30 when i execute > manually. Is there any different multiplicati

Re: A Trivial Question

2011-09-28 Thread Chris Rebert
On Wed, Sep 28, 2011 at 2:53 PM, Tayfun Kayhan wrote: > I accidentally wrote such a code (below) while trying to write sth else for > my application but i am now just wondering much how to run the class Foo, if > it is possible. Is not it weird that Python does not give any error when I > run it ?

Re: Question on Manipulating List and on Python

2011-09-29 Thread Chris Rebert
On Thu, Sep 29, 2011 at 9:11 AM, Subhabrata Banerjee wrote: > Dear Group, > > I have two questions one on list manipulation and other on Python. > > (i) I have a file of lists. Now, the first digit starts with a number > or index, like, > > [001, "Obama", "USA", "President"] > [002  "Major", "UK",

Re: Counting the number of call of a function

2011-09-29 Thread Chris Rebert
On Thu, Sep 29, 2011 at 10:08 AM, Laurent Claessens wrote: >   Hello > > >   Is it possible to count the number of time a function is called ? > Of course, if I've access to the source code, it's easy. > > I tried the following : > > def foo(): >    print "foo !" > > > class wraper(object): >    d

Re: [OT] Off-Topic Posts and Threads on the Python Mailing List

2011-09-29 Thread Chris Rebert
On Thu, Sep 29, 2011 at 2:33 PM, Westley Martínez wrote: > I'm kind of new to the whole mailing list thing, but they seem to be a > lot more lenient than internet forums about most things.  I've noticed > that sometimes Off-topic posts can get a little out of hand.  I guess > it's not really a big

Re: overloading operators for a function object

2011-09-30 Thread Chris Rebert
On Fri, Sep 30, 2011 at 9:50 PM, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): >  def func(): pass > >  def __eq__(other): >    if other == "check":  return True >    return False >

Re: executing arbitrary statements

2011-10-01 Thread Chris Rebert
On Fri, Sep 30, 2011 at 11:31 PM, Jason Swails wrote: > Hello everyone, > > I'm probably missing something pretty obvious, but I was wondering if there > was a way of executing an arbitrary line of code somehow (such as a line of > code based on user-input).  There's the obvious use of "eval" that

Re: getattr and method name

2011-10-02 Thread Chris Rebert
On Sun, Oct 2, 2011 at 3:02 PM, Kevin Walzer wrote: > I'm seeing a very odd error in an application I'm developing using Python > 2.7.2, on Mac OS 10.7. > > This application uses a wrapper method to look up other method names via > getattr and then call those methods. I have not previously had an

Re: timedelta is squicking me out

2011-10-02 Thread Chris Rebert
On Sun, Oct 2, 2011 at 7:27 PM, Phlip wrote: > has anyone invented a system like R*by's ActiveSupport's 5.years.ago, > 42.minutes.since ? > > (Yes, I'm aware the notation will be different!) If something involves Python and nontrivial chronology, then mxDateTime is the go-to library. And indeed,

Re: Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str

2011-10-03 Thread Chris Rebert
On Sun, Oct 2, 2011 at 11:45 PM, Wong Wah Meng-R32813 wrote: > Hello guys, > > I am migrating my application from python 1.5.2 to 2.7.1. I encountered an > error when I run some commands (I put in debug statement however, not able to > trace down to which line of code that cause it to generate a

Re: packages, modules and double imports - oh my!

2011-10-03 Thread Chris Rebert
On Mon, Oct 3, 2011 at 3:11 AM, Chris Withers wrote: > Hi All, > > The attached package gives that smallest possible example of problems I'm > hitting with some SQLAlchemy declarative classes. > > In short, I want to be able to do: > > python -m pack.module and have if the __name__=='__main__' blo

Re: how to call java methods in python

2011-10-04 Thread Chris Rebert
On Tue, Oct 4, 2011 at 12:14 AM, masood shaik wrote: > Hi >  I am trying out my hand on accessing java methods in python. here is > my piece of code.. > > Calculator.java > --- > public class Calculator { > >    public Calculator(){ > >    } > >    public double calculateTip(double cos

Re: Is exec() also not used in python 2.7.1 anymore?

2011-10-04 Thread Chris Rebert
On Tue, Oct 4, 2011 at 12:51 AM, Wong Wah Meng-R32813 wrote: > In migrating my application from python 1.5.2 to 2.7.1, one of my modules > breaks when I import it. Here is the line where it breaks. Can I have a > quick check if this built-in function still supported in python 2.7.1 Er, `exec` is

Re: "IX" as shorthand for "Interface"

2011-10-08 Thread Chris Rebert
On Sat, Oct 8, 2011 at 9:21 PM, Eric Snow wrote: > I'm writing a bunch of classes that have "Interface" in the name and > find that the length of the subsequent names is starting to get in the > way of readability (I don't really care about saving keystrokes).  Is > "IX" conventional enough to use

Re: Using Python xmlrpclib to build XMLRPC clients for a server with variable RPC names

2011-10-09 Thread Chris Rebert
On Sun, Oct 9, 2011 at 6:30 AM, John P. Crackett wrote: > I need to write prototype XMLRPC clients using xmlrpclib for a server > that has variable RPC names and I'd like to use Python as the > prototyping tool.  I've searched but can't find any relevant advice > online.  Any pointers would be gra

Re: Opportunity missed by Python ?

2011-10-13 Thread Chris Rebert
On Thu, Oct 13, 2011 at 3:07 AM, Chris Angelico wrote: > On Thu, Oct 13, 2011 at 8:45 PM, candide wrote: >> Dart is the very new language created by Google to replace Javascript. >> So Python was not able to do the job? Or may be they don't know about Python >> at Google ;) ? >> > > Python, as I

Re: .py and .pyc files in read-only directory

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 11:04 AM, Terry wrote: > I'm having a problem with my iPhone/iPad app, Python Math, a Python > 2.7 interpreter. All the Python modules are delivered in what Apple > calls the app bundle. They are in a read-only directory. This means > that Python cannot write .pyc files to

Re: How to test if object is an integer?

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 6:05 PM, Chris Angelico wrote: > 2011/10/15 惜悯 : >> retrun True if type(i) is int else False > > That tests if the object is already an int; the OP asked if a string > contains an integer. Additionally: * the if-then-else there is unnecessary since `type(i) is int` already

Re: Language Enhancement Idea to help with multi-processing (your opinions please)

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 6:23 PM, alex23 wrote: > On Oct 14, 4:56 pm, Carl Banks wrote: >> But you can see that, fully realized, syntax like that can do much more >> than can be done with library code. > > Well sure, but imaginary syntax can do _anything_. That doesn't mean > it's possible within

Re: Reading a file into a data structure....

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 7:59 PM, MrPink wrote: > This is what I have been able to accomplish: > > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError: >        return False > > f = open("powerball.txt", "r") > lines = f.readlines() > f.close() > > dDrawings = {}

Re: I am a newbie for python and try to understand class Inheritance.

2011-10-15 Thread Chris Rebert
On Fri, Oct 14, 2011 at 11:20 PM, wrote: > Test.py > #!/usr/bin/python > from my_lib import my_function > class my_class(my_function.name): Why are you subclassing my_function.name and not just my_function? >    def __initial__(self, name); >         pass The initializer method should be named

Re: I am a newbie for python and try to understand class Inheritance.

2011-10-15 Thread Chris Rebert
On Sat, Oct 15, 2011 at 12:09 AM, Jason Swails wrote: > For instance, let's say you want to deal with shapes.  You can define a > shape via a class > > class Shape(object): >    """ Base shape class """ > Now we get into inheritance.  Let's suppose that we want a specific type of > shape.  For i

Re: I am a newbie for python and try to understand class Inheritance.

2011-10-15 Thread Chris Rebert
On Sat, Oct 15, 2011 at 12:59 AM, wrote: > On 10月15日, 上午12时04分, Chris Rebert wrote: >> On Fri, Oct 14, 2011 at 11:20 PM,   wrote: >> >    my_class.main() >> >> Your class doesn't define any method named "main" (you only defined >> test() and _

Re: type(), modules: clarification please

2011-10-15 Thread Chris Rebert
On Sat, Oct 15, 2011 at 4:00 PM, Shane wrote: > Hi, > > When one writes, > >> className='Employee' >> baseClasses = ... >> dictionary = { ... } >> newClass = type( className, , dictionary) > > in what module does newClass belong? If it's the current module That does seem to be the case. > what c

Re: fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())

2011-10-19 Thread Chris Rebert
On Wed, Oct 19, 2011 at 1:06 AM, aspineux wrote: > hi > import pytz from datetime import datetime pytz.timezone('GMT0').fromutc(datetime.utcnow()) > datetime.datetime(2011, 10, 19, 7, 54, 45, 579125, > tzinfo=)  pytz.timezone('UTC').fromutc(datetime.utcnow()) > Traceback (most

Re: how to change the order of a button, static text or other components

2011-10-20 Thread Chris Rebert
On Thu, Oct 20, 2011 at 6:08 PM, install...@189.cn wrote: > what i want to do is,when i press a button, i change the order of > selected components,how to do this? Which GUI toolkit are you using? Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: SMS api for python

2011-10-21 Thread Chris Rebert
On Fri, Oct 21, 2011 at 12:10 AM, Pankaj wrote: > I want to make an api that would recieve the SMS text from the user > and process it then send the result back to the use. Is there any api > that I can use to do this?? There would seem to be several options: http://pypi.python.org/pypi?%3Aaction

Re: How to isolate a constant?

2011-10-22 Thread Chris Rebert
On Sat, Oct 22, 2011 at 5:26 PM, Gnarlodious wrote: > Say this: > > class tester(): Style note: either have it explicitly subclass `object`, or don't include the parens at all. Empty parens for the superclasses is just weird. >        _someList = [0, 1] >        def __call__(self): >            

Re: What is wrong with my code?

2011-10-23 Thread Chris Rebert
On Sun, Oct 23, 2011 at 3:03 AM, apometron wrote: > import os > nome = sys.argv[1] You did not `import sys`, so you'll get a NameError there. > final = nome > for i in nome: >    print i >    if nome[i] = "_": >        final[i] = " " Strings aren't mutable in Python; you can't assign to slices

Re: python32 to write file

2011-10-23 Thread Chris Rebert
2011/10/23 水静流深 <1248283...@qq.com>: >     book=open('c:\'+str1,'w')  #  i  change it > when i run it  in  python32,the output is  : > book=open('c:\'+str1,'w') > invalid  syntax,what is wrong? Your problem is not at all Python 3-specific. Backslashes are used for escape sequences in string l

Re: How to use shell return value like $? In python?

2011-10-23 Thread Chris Rebert
On Sun, Oct 23, 2011 at 7:51 PM, wrote: > On Oct 23, 7:44 pm, aaabb...@hotmail.com wrote: >> exp: >> os.system('ls -al') >> #I like to catch return value after this command. 0 or 1,2,3 >> does python support to get "$?"? >> then I can use something like: >>  If $?==0: > So for what I do is:

Re: What is wrong with my code?

2011-10-23 Thread Chris Rebert
On Sun, Oct 23, 2011 at 8:21 PM, apometron wrote: > Sorry to continue discussing my thread on this list, I already subbed on the > Tutor list > but I need to reply and if possible, some ideas of why it dont works. Now it > is another > thing, entirely. Rename1.py and Rename2.py works, but why Rena

Re: CSV writer question

2011-10-23 Thread Chris Rebert
On Sun, Oct 23, 2011 at 10:18 PM, Jason Swails wrote: > Hello, > > I have a question about a csv.writer instance.  I have a utility that I want > to write a full CSV file from lots of data, but due to performance (and > memory) considerations, there's no way I can write the data sequentially. > Th

Re: UnicodeError instead of UnicodeWarning

2011-10-25 Thread Chris Rebert
2011/10/25 Michael Ströder : > HI! > > For tracking the cause of a UnicodeWarning I'd like to make the Python > interpreter to raise an UnicodeError exception with full stack trace. Is there > a short trick to achieve this? from exceptions import UnicodeWarning from warnings import filterwarnings

Re: passing Python data to a javascript function

2011-10-26 Thread Chris Rebert
On Wed, Oct 26, 2011 at 7:25 PM, Bill Allen wrote: > > Benjamin, > > I was afraid I was doing that.   I have simplified it quite a bit, still not > getting the output I am looking for.   I am down to that I am not passing > the value in the onload=showPID() call correctly.  I know this is getting

Re: Forking simplejson

2011-10-27 Thread Chris Rebert
On Thu, Oct 27, 2011 at 6:55 AM, Amirouche Boubekki wrote: > >>> +---+---+ >>> | Python protocol | JSON | >>> | or special case | | >>> +===+===+ >>> | (ø) __json__ | see (ø) | >>> +---+---| >>>      | map        

Re: Forking simplejson

2011-10-27 Thread Chris Rebert
On Wed, Oct 26, 2011 at 2:14 AM, Amirouche Boubekki wrote: > Héllo, > > I would like to fork simplejson [1] and implement serialization rules based > on protocols instead of types [2], plus special cases for protocol free > objects, that breaks compatibility. The benefit will be a better API for >

<    1   2   3   4   5   6   7   8   9   10   >