Re: Fatal Python error

2013-05-31 Thread nn
On May 29, 10:05 am, Joshua Landau wrote: > On 29 May 2013 14:02, Dave Angel wrote: > > > On 05/29/2013 08:45 AM, Oscar Benjamin wrote: > > Joshua:  Avoid doing anything complex inside an exception handler. > > Unfortunately, Ranger (the file manager in question) wraps a lot of stuff > in one big

Re: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread nn
On May 23, 2:42 pm, Dave Angel wrote: > On 05/23/2013 11:26 AM, Carlos Nepomuceno wrote: > > > > >> Date: Thu, 23 May 2013 06:44:05 -0700 > >> Subject: Re: PEP 378: Format Specifier for Thousands Separator > >> From: prueba...@latinmail.com > >> To: python-

Re: PEP 378: Format Specifier for Thousands Separator

2013-05-23 Thread nn
On May 22, 6:31 pm, Carlos Nepomuceno wrote: > > > > Date: Wed, 22 May 2013 13:26:23 -0700 > > Subject: Re: PEP 378: Format Specifier for Thousands Separator > > From: prueba...@latinmail.com > > To: python-l...@python.org > [...] > > > Maybe a cformat(form

Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread nn
On May 22, 2:30 pm, Ned Batchelder wrote: > On 5/22/2013 10:58 AM, Steven D'Aprano wrote: > > > On Wed, 22 May 2013 05:45:12 -0500, Skip Montanaro wrote: > > >> I didn't mean to create a tempest in a teapot.  I was away from > >> comp.lang.python, python-bugs, and python-dev for a few years.  In >

Re: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-22 Thread nn
On May 22, 6:35 am, Skip Montanaro wrote: > >> Is this tutorial outdated or this still an issue? > > >> [1] > >>http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting > > > That tutorial is out of date.  %-formatting isn't being removed. > > OTOH, PEP 3101 also mentions deprecati

Re: Weird behaviour?

2013-04-22 Thread nn
On Apr 21, 9:19 pm, Steven D'Aprano wrote: > On Mon, 22 Apr 2013 10:56:11 +1000, Chris Angelico wrote: > > You're running this under Windows. The convention on Windows is for > > end-of-line to be signalled with \r\n, but the convention inside Python > > is to use just \n. With the normal use of b

Re: xlrd 0.9.2 released!

2013-04-10 Thread nn
On Apr 9, 3:38 pm, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlrd 0.9.2: > > http://pypi.python.org/pypi/xlrd/0.9.2 > > This release includes the following changes: > > - Fix some packaging issues that meant docs and examples were missing > from the tarball. > > - F

Re: Do you feel bad because of the Python docs?

2013-02-26 Thread nn
On Feb 26, 11:19 am, notbob wrote: > On 2013-02-26, Steven D'Aprano wrote: > > > "The Python documentation is bad, and you should feel bad". > > Ahh!  A point at which I can interject. > > As a rank green python noob, I definitely hava an opinion on python > documentation and it's not entirely fl

Re: Fairly OT: Why "flufl"?

2013-02-04 Thread nn
On Feb 4, 10:10 am, Chris Angelico wrote: > This isn't particularly related to the post I'm quoting, it's more a > point of curiosity. > > On Mon, Feb 4, 2013 at 10:53 AM, João Bernardo wrote: > > Re: [Python-ideas] constant/enum type in stdlib > > > I have my own implementation with a basic api

Re: print or write on a text file ?

2012-10-01 Thread nn
On Sep 28, 2:42 pm, Franck Ditter wrote: > Hi ! > Here is Python 3.3 > Is it better in any way to use print(x,x,x,file='out') > or out.write(x) ? Any reason to prefer any of them ? > There should be a printlines, like readlines ? > Thanks, > >     franck There is out.writelines(lst) -- http://m

Re: Working with Cursors

2012-04-17 Thread nn
On Apr 17, 2:11 pm, timlash wrote: > Searched the web and this forum without satisfaction.  Using Python 2.7 and > pyODBC on Windows XP I can get the code below to run and generate two cursors > from two different databases without problems.  Ideally, I'd then like to > join these result cursor

Re: Working with Cursors

2012-04-17 Thread nn
On Apr 17, 2:11 pm, timlash wrote: > Searched the web and this forum without satisfaction.  Using Python 2.7 and > pyODBC on Windows XP I can get the code below to run and generate two cursors > from two different databases without problems.  Ideally, I'd then like to > join these result cursor

Re: how to count the total number of strings (in the list) used in Python?

2012-04-17 Thread nn
On Apr 16, 3:00 pm, Chinesekidz wrote: > Hello! > > I would like to know how to write the program to count the total > number of strings (in the list) used in Python.. > > for example: > > list:['1','2','3','4'] > > for l in range(4): >      num=input("list:"+list[l]+"(between 1 and 4):") >      i

Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 12:26 pm, Alain Ketterlin wrote: > nn writes: > >> > for item in tag23gr: > >> > ...        value, key = tuple(item) > >> > ...        if(g23tag.get(key)): > >> > ...                g23tag[key].append(value) > >> >

Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 11:02 am, Alain Ketterlin wrote: > python writes: > > tag23gr is a list of lists each with two items. > > g23tag is an empty dictionary when I run the for loop below. > > When is is complete each key is a graphic name who's values are a list > > of tags. > > > for item in tag23gr: > > .

Re: Python-URL! - weekly Python news and links (Mar 31)

2012-04-02 Thread nn
On Mar 31, 11:38 am, Cameron Laird wrote: > I pine for the fjords. > > And it's time to bring "Python-URL!" to a close.  "Python-URL!", which > Jean-Claude Wippler and I appear to have launched in 1998, has reached > the end of its utility.  We still have many loyal and enthusiastic > readers--one

Re: Python math is off by .000000000000045

2012-02-22 Thread nn
On Feb 22, 1:13 pm, Alec Taylor wrote: > Simple mathematical problem, + and - only: > > >>> 1800.00-1041.00-555.74+530.74-794.95 > > -60.9500045 > > That's wrong. > > Proofhttp://www.wolframalpha.com/input/?i=1800.00-1041.00-555.74%2B530.74-... > -60.95 aka (-(1219/20)) > > Is there a reas

Re: Multiplication error in python

2011-09-27 Thread nn
On Sep 27, 1:21 pm, 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 multiplication pattern i

Re: convert time

2011-09-12 Thread nn
On Sep 11, 1:00 am, Steven D'Aprano wrote: > 守株待兔 wrote: > > how can i convert "Dec 11" into  2011-12? > > if my_str == "Dec 11": >     return 1999  # 2011 - 12 > > Does that help? > > But seriously... 2011-12 is not a proper date, so the simplest way is > probably something like this: > > def con

Re: testing if a list contains a sublist

2011-08-16 Thread nn
On Aug 16, 8:23 am, Alain Ketterlin wrote: > Roy Smith writes: > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > > import re > > > def sublist(l1, l2): > >     s1 = ''.join(map(str, l1)) > >     s2 = ''.join(map(str

Re: Implicit initialization is EVIL!

2011-07-05 Thread nn
On Jul 4, 11:35 am, Robin Becker wrote: > On 03/07/2011 23:21, Chris Angelico wrote: > . > > > var(0x14205359) x   # Don't forget to provide an address where the > > object will be located > > x=42 > > > did you forget to specify the memory bank and computer (and presumably planet

Re: What is the most efficient way to find similarities and differences between the contents of two lists?

2011-06-13 Thread nn
On Jun 13, 11:06 am, Zachary Dziura wrote: > Hi all. > > I'm writing a Python script that will be used to compare two database > tables. Currently, those two tables are dumped into .csv files, > whereby my code goes through both files and makes comparisons. Thus > far, I only have functionality co

Re: generate properties code in class dynamically

2011-05-12 Thread nn
On May 12, 9:11 am, JamesEM wrote: > Hello, > I have a python class that contains a dictionary. > I would like to use python properties to access the elements of the > dictionary. > This could be achieved as follows: > > class MyClass(object): > >     def __init__(self): >         self.d = {} >  

Re: string formatting

2011-05-06 Thread nn
On May 6, 8:10 am, Web Dreamer wrote: > Chris Rebert a écrit ce vendredi 6 mai 2011 11:23 dans > : > > > > > I'm not them, but: > > "Note: The formatting operations described here [involving %] are > > obsolete and may go away in future versions of Python. Use the new > > String Formatting [i.e.

Re: Today's fun and educational Python recipe

2011-05-05 Thread nn
On May 4, 2:17 pm, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing > algorithm:http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and > well-written:http://en.wikipedia.org/wiki/Bloom_filter > > It turns out that people in the 1970's were prett

Re: Finding empty columns. Is there a faster way?

2011-04-22 Thread nn
On Apr 21, 4:32 pm, Jon Clements wrote: > On Apr 21, 5:40 pm, nn wrote: > > > > > > > > > > > time head -100 myfile  >/dev/null > > > real    0m4.57s > > user    0m3.81s > > sys     0m0.74s > > > time ./repnullsalt.py &#

Finding empty columns. Is there a faster way?

2011-04-21 Thread nn
time head -100 myfile >/dev/null real0m4.57s user0m3.81s sys 0m0.74s time ./repnullsalt.py '|' myfile 0 1 Null columns: 11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68 real1m28.94s user1m28.11s sys 0m0.72s import sys def main(): with open(sys.argv[2

Re: replace regex in file using a dictionary

2011-04-05 Thread nn
On Apr 5, 3:59 am, Martin De Kauwe wrote: > Hi, > > So i want to replace multiple lines in a text file and I have reasoned > the best way to do this is with a dictionary. I have simplified my > example and broadly I get what I want however I am now printing my > replacement string and part of the

Re: better way to do this in python

2011-04-04 Thread nn
On Apr 3, 8:06 am, Mag Gam wrote: > Thanks for the responses. > > Basically, I have a large file with this format, > > Date INFO username command srcipaddress filename > > I would like to do statistics on: > total number of usernames and who they are > username and commands > username and filename

Re: What is the best book to learn Python from Perl and C++ background

2011-03-04 Thread nn
On Mar 4, 12:49 pm, Ignoramus20691 wrote: > I bought a "Hello World!" book for my 9 year old son. The book teached > "programming for kids" and it does it in Python. > > I do not know any Python, but I am very comfortable with C++ and perl. > I wrote a little over 100k lines of perl. > > I want to

Re: Fun with 'str' and 'bytes'

2011-03-04 Thread nn
On Mar 4, 7:32 am, "Frank Millman" wrote: > Hi all > > I want to create a cookie containing a session id. In python 2.6 I had the > following - > > from __future__ import unicode_literals > session_id = b64encode(urandom(20)) > response_headers.append( >     (b'Set-Cookie', b'sid="{0}"'.format(ses

Re: Executing functions

2011-02-11 Thread nn
On Feb 11, 9:15 am, DataSmash wrote: > Can someone help me understand why Example #1 & Example #2 will run > the functions, > while Example #3 DOES NOT? > Thanks for your time! > R.D. > > def One(): >     print "running fuction 1" > def Two(): >     print "running fuction 2" > def Three(): >     p

Re: itertools.groupby usage to get structured data

2011-02-07 Thread nn
On Feb 5, 7:12 am, Peter Otten <__pete...@web.de> wrote: > Slafs wrote: > > Hi there! > > > I'm having trouble to wrap my brain around this kind of problem: > > > What I have : > >   1) list of dicts > >   2) list of keys that i would like to be my grouping arguments of > > elements from 1) > >   3

Re: move to end, in Python 3.2 Really?

2011-01-18 Thread nn
On Jan 18, 12:20 am, Raymond Hettinger wrote: > On Jan 17, 6:51 pm, nn wrote: > > > ...But the api on this baffles me a bit: > > > >>> d = OrderedDict.fromkeys('abcde') > > >>> d.move_to_end('b', last=False) > > >>&g

move to end, in Python 3.2 Really?

2011-01-17 Thread nn
I somehow missed this before. I like most of the additions from Raymond Hettinger. But the api on this baffles me a bit: >>> d = OrderedDict.fromkeys('abcde') >>> d.move_to_end('b', last=False) >>> ''.join(d.keys) 'bacde' I understand that "end" could potentially mean either end, but would "mov

Re: decouple copy of a list

2010-12-10 Thread nn
On Dec 10, 8:48 am, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk Not knowing the particulars, you may have to use: import copy b=copy.deepcopy(a) -- http://mail.python.org/mailman/listinfo/pyt

Re: Deprecation warnings (2.7 -> 3 )

2010-12-10 Thread nn
On Dec 10, 11:17 am, nn wrote: > On Dec 9, 10:15 pm, rusi wrote: > > > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > > deprecation warnings > > > Heres the (first) set > > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash

Re: Deprecation warnings (2.7 -> 3 )

2010-12-10 Thread nn
On Dec 9, 10:15 pm, rusi wrote: > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > deprecation warnings > > Heres the (first) set > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > in 3.x > DeprecationWarning: callable() not supported in 3.x; use isinstance(x

Re: completely implicit interpolation based on a frame object

2010-12-09 Thread nn
On Dec 9, 2:29 am, Edward Peschko wrote: > >> Any ideas would be great on this, including pitfalls that people see > >> in implementing it. > > >http://docs.python.org/library/string.html#template-strings > > > regards > >  Steve > > Steve, > > Thanks for the tip, I did look at templates and decid

Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread nn
On Dec 7, 10:52 am, gst wrote: > Hi, > > I met a situation where I was passing an object created in/with an > upper level module class to a lower level module class' instance in > one of its __init__ argument and saving a ref of the upper object in > that lower level class' new instance. > > But i

Re: Bunch 2.0 - a dict with a default

2010-11-19 Thread nn
On Nov 18, 8:45 pm, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > >         map = Map() >        

Re: Question about expression evaluation

2010-11-08 Thread nn
On Nov 8, 11:17 am, Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- >   File "/var/www/myproj/account/views.py", line 54, in account >     if request.account.is_instructor and request.account.contact and > request.account.contact.relationsh

Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread nn
On Oct 28, 12:33 pm, "cbr...@cbrownsystems.com" wrote: > On Oct 28, 9:23 am, John Posner wrote: > > > > > On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: > > > > It's clear but tedious to write: > > > > if 'monday" in days_off or "tuesday" in days_off: > > >      doSomething > > > > I cur

Re: Why "flat is better than nested"?

2010-10-27 Thread nn
On Oct 25, 4:18 pm, Ethan Furman wrote: > kj wrote: > > In Steve Holden > > writes: > > >>> On Oct 25, 5:07 am, kj wrote: > In "The Zen of Python", one of the "maxims" is "flat is better than > nested"?  Why?  Can anyone give me a concrete example that illustrates > this point?

Re: Question regarding python2.5 migration from windows xp to windows 7

2010-10-14 Thread nn
On Oct 14, 2:37 am, python_tsp wrote: > Hi, > > We have a Python based test framework which is being used in various > projects. > > Our current environment is > Python (ver 2.5.1) > wxPython (wxPython2.8-win32-ansi-2.8.6.0-py25) > pywin32-210.win32-py2.5 > vcredist_x86.exe > pyserial-2.2 > > Our

Re: Many newbie questions regarding python

2010-10-08 Thread nn
On Oct 7, 7:10 pm, Rogério Brito wrote: > Hi there. > > I am used to some languages like C, but I am just a complete newbie with > Python > and, while writing some small snippets, I had encountered some problems, with > which I would sincerely appreciate any help, since I appreciate this language

Re: Help with sets

2010-10-05 Thread nn
> Semantic web.  I did get a bit confused in reading about the concept of > sets in python and why you would use them instead of a dictionary for Sets are faster and more convenient to do intersections, unions, differences. They also use less space than dictionaries. Finally they also help conveyi

Re: lists and list item matches (ghost wodgame)

2010-09-24 Thread nn
On Sep 23, 8:46 pm, Baba wrote: > On Sep 23, 8:13 pm, nn wrote: > > > > > On Sep 23, 1:25 pm, Baba wrote: > > > > On Sep 23, 4:17 pm, nn wrote: > > > > > On Sep 23, 10:56 am, nn wrote: > > > > > > On Sep 22, 6:39

Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 23, 1:25 pm, Baba wrote: > On Sep 23, 4:17 pm, nn wrote: > > > > > On Sep 23, 10:56 am, nn wrote: > > > > On Sep 22, 6:39 pm, Baba wrote: > > > > > On Sep 22, 9:18 pm, Baba wrote: > > > > > > On Sep 22, 3:

Re: collections.namedtuple: conflicting instances?

2010-09-23 Thread nn
On Sep 23, 1:40 pm, Chris Rebert wrote: > On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett > wrote: > > > > >  I've noticed that it's possible to create conflicting instances of the > > collections.namedtuple class: > > >  from collections  import namedtuple as nt > >  IX = nt('X', 'a b') > >  

Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 23, 10:56 am, nn wrote: > On Sep 22, 6:39 pm, Baba wrote: > > > > > On Sep 22, 9:18 pm, Baba wrote: > > > > On Sep 22, 3:38 pm, nn wrote: > > > > > On Sep 21, 6:39 pm, Baba wrote: > > > > > > Hi > > > > > >

Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 22, 6:39 pm, Baba wrote: > On Sep 22, 9:18 pm, Baba wrote: > > > > > On Sep 22, 3:38 pm, nn wrote: > > > > On Sep 21, 6:39 pm, Baba wrote: > > > > > Hi > > > > > query level: beginner > > > > > as part of a

Re: lists and list item matches (ghost wodgame)

2010-09-22 Thread nn
On Sep 21, 6:39 pm, Baba wrote: > Hi > > query level: beginner > > as part of a learning exercise i have written code that: > > a) asks for a single letter input (assumption: only 1 letter wil be > entered) > b) adds that letter to list1 and then goes through list2 and checks: > >     1) if any it

Re: business date and calendar libraries?

2010-09-15 Thread nn
On Sep 13, 3:02 pm, David Robinow wrote: > On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers wrote: > > I'm wondering what libraries people would use to answer the following > > questions relating to business days: > > > - on a less-naive level; same question but taking into account public > > holid

Re: Ugh! Python 3.1.x and MySQL

2010-09-10 Thread nn
On Sep 10, 12:27 pm, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like > to use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. >

Re: Minimum and Maximum of a list containing floating point numbers

2010-09-07 Thread nn
On Sep 6, 10:31 pm, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > >     >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfu

Re: passing variables as object attributes

2010-08-16 Thread nn
On Aug 16, 10:08 am, Vikas Mahajan wrote: > On 16 August 2010 19:23, Nitin Pawar wrote:> you > would need to define a class first with its attiributes and then you may > > want to initiate the variables by calling the class initilializer > > Actually I have to dynamically add attributes to a obj

Re: passing variables as object attributes

2010-08-16 Thread nn
On Aug 16, 10:08 am, Vikas Mahajan wrote: > On 16 August 2010 19:23, Nitin Pawar wrote:> you > would need to define a class first with its attiributes and then you may > > want to initiate the variables by calling the class initilializer > > Actually I have to dynamically add attributes to a obj

Re: Regular expression issue

2010-08-09 Thread nn
On Aug 9, 9:18 am, genxtech wrote: > On Aug 8, 7:34 pm, Tim Chase wrote: > > > > > On 08/08/10 17:20, genxtech wrote: > > > > if re.search(search_string, in_string) != None: > > > While the other responses have addressed some of the big issues, > > it's also good to use > > >    if thing_to_test

Re: new to python - trouble calling a function from another function

2010-08-06 Thread nn
On Aug 5, 2:01 pm, Daniel Urban wrote: > > I'm building an elevator simulator for a class assignment. I recently ran > > into a roadblock and don't know how to fix it. For some reason, in my > > checkQueue function below, the call to self.goUp() is never executed. It is > > on the last line of cod

Re: The inverse of .join

2010-06-17 Thread nn
Neil Cerutti wrote: > What's the best way to do the inverse operation of the .join > function? > > -- > Neil Cerutti split -- http://mail.python.org/mailman/listinfo/python-list

Re: Missing DLL in win98

2010-06-04 Thread nn
On Jun 4, 9:53 am, Spyder42 wrote: > On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes > > wrote: > >> So your response is either, you don't know if there is a fix, or 'No > >> way in h377.' You couldn't figure out by my post that I already knew > >> that? > > >Let me paraphrase my answer: > >

Re: Why these don't work??

2010-04-08 Thread nn
M. Hamed wrote: > I'm trying the following statements that I found here and there on > Google, but none of them works on my Python 2.5, are they too old? or > newer? > > "abc".reverse() > import numpy reverse does not work on strings but does work on lists: >>> x=list("abc") >>> x.reverse() >>>

Re: Unicode blues in Python3

2010-03-24 Thread nn
Antoine Pitrou wrote: > Le Tue, 23 Mar 2010 10:33:33 -0700, nn a écrit : > > > I know that unicode is the way to go in Python 3.1, but it is getting in > > my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py >

Re: Unicode blues in Python3

2010-03-24 Thread nn
Steven D'Aprano wrote: > On Tue, 23 Mar 2010 11:46:33 -0700, nn wrote: > > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > What do you mean "work"? >

Re: Unicode blues in Python3

2010-03-24 Thread nn
Martin v. Loewis wrote: > nn wrote: > > > > Stefan Behnel wrote: > >> nn, 23.03.2010 19:46: > >>> Actually what I want is to write a particular byte to standard output, > >>> and I want this to work regardless of where that output gets sent to. &g

Re: Unicode blues in Python3

2010-03-23 Thread nn
Stefan Behnel wrote: > nn, 23.03.2010 19:46: > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > I am aware that I could do > > open('nnout','w',en

Re: Unicode blues in Python3

2010-03-23 Thread nn
Gary Herron wrote: > nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > Python3 make a distinction between bytes and string(i.e., un

Re: Unicode blues in Python3

2010-03-23 Thread nn
Rami Chowdhury wrote: > On Tuesday 23 March 2010 10:33:33 nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py > &g

Unicode blues in Python3

2010-03-23 Thread nn
I know that unicode is the way to go in Python 3.1, but it is getting in my way right now in my Unix scripts. How do I write a chr(253) to a file? #nntst2.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) print(mychar) > ./nntst2.py ISO8859-1 ý > ./nntst2.py >nnout2 Traceback (mo

Re: short-circuiting any/all ?

2010-03-22 Thread nn
kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invali

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-17 Thread nn
Michael Torrie wrote: > david jensen wrote: > > of course, changing nn's to: > > def getOutcomes(myList=[2,5,8,3,5]): > >low_id = int(myList[0]>myList[1]) > >amountToShare = 2*myList[low_id] > >remainder = myList[not low_id]-myList[low_id] > >tail=list(myList[2:]) > >outcomes

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread nn
david jensen wrote: > ... and of course i screwed up my outcomes... that should read > outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] For starters: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder

Re: related lists mean value (golfed)

2010-03-09 Thread nn
Peter Otten wrote: > Michael Rudolf wrote: > > > Am 09.03.2010 13:02, schrieb Peter Otten: > > [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] > >> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > >> Peter > > > > ... pwned. > > Should be the fastest and shortest way to do it. > > It may be short,

Re: loop over list and process into groups

2010-03-05 Thread nn
mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > 'Interface', > > 'Gi9/6', > > 'Po2', > > 'Po3', > > 'Po306', > > 'VLAN4068', > > 'Interface', > > 'Gi9/6', > > 'VLAN4069', > > 'Interface', > > 'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > >

Re: Evaluate my first python script, please

2010-03-04 Thread nn
On Mar 4, 2:30 pm, MRAB wrote: > Pete Emerson wrote: > > I've written my first python program, and would love suggestions for > > improvement. > > > I'm a perl programmer and used a perl version of this program to guide > > me. So in that sense, the python is "perlesque" > > > This script parses /

Re: loop over list and process into groups

2010-03-04 Thread nn
lbolla wrote: > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > [ {'vlan_or_intf': 'VLAN2021'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Po1'}, > >  {'vlan_or_intf': 'Po306'}, > >  {'vlan_or_intf': 'VLAN2022'}, > >  {'vlan_or_intf': 'Interface'}, > >  {'vlan_or_intf': 'Gi7/33'}, >

Re: Can I specify regex group to return float or int instead of string?

2010-02-25 Thread nn
On Feb 25, 12:20 pm, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote: > > On Feb 25, 9:41 am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > >> > I have a regular expression that searches for some numbers and puts >

Re: A more pythonish code

2010-02-25 Thread nn
prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more graceful

Re: string to list when the contents is a list

2010-02-18 Thread nn
Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get:

Re: Need help with a program

2010-01-29 Thread nn
Johann Spies wrote: > On Thu, Jan 28, 2010 at 07:07:04AM -0800, evilweasel wrote: > > Hi folks, > > > > I am a newbie to python, and I would be grateful if someone could > > point out the mistake in my program. Basically, I have a huge text > > file similar to the format below: > > > > AGACTC

Re: Need help with a program

2010-01-28 Thread nn
Arnaud Delobelle wrote: > nn writes: > > > On Jan 28, 10:50 am, evilweasel wrote: > >> I will make my question a little more clearer. I have close to 60,000 > >> lines of the data similar to the one I posted. There are various > >> numbers next to the se

Re: Need help with a program

2010-01-28 Thread nn
On Jan 28, 10:50 am, evilweasel wrote: > I will make my question a little more clearer. I have close to 60,000 > lines of the data similar to the one I posted. There are various > numbers next to the sequence (this is basically the number of times > the sequence has been found in a particular samp

Re: ctypes for AIX

2010-01-26 Thread nn
On Jan 25, 6:36 pm, "Waddle, Jim" wrote: > Chris, > Thanks for responding to my email. > I apologize for the remark about python only being developed for windows. I > got the impression when I was looking at the ActivePython web site and saw > that the version of python that they had available w

Re: Arrrrgh! Another module broken

2010-01-19 Thread nn
On Jan 18, 11:37 am, Grant Edwards wrote: > On 2010-01-18, Jive Dadson wrote: > > > I just found another module that broke when I went to 2.6.  Gnuplot. > > Apparently one of its routines has a parameter named "with."  That used > > to be okay, and now it's not. > > I remember seeing depreicated

Re: Py 3: Terminal script can't find relative path

2010-01-19 Thread nn
On Jan 19, 8:03 am, Gnarlodious wrote: > On Jan 18, 4:21 pm, John Bokma wrote: > > > Gnarlodious writes: > > > I am running a script in a browser that finds the file in subfolder > > > Data: > > > > Content=Plist('Data/Content.plist') > > > > However, running the same script in Terminal errors:

Re: Which is more pythonic?

2009-12-04 Thread nn
On Dec 3, 10:41 am, Filip Gruszczyński wrote: > I have just written a very small snippet of code and started thinking, > which version would be more pythonic. Basically, I am adding a list of > string to combo box in qt. So, the most obvious way is: > > for choice in self.__choices: >         choi

Re: Question about file objects...

2009-12-03 Thread nn
On Dec 2, 6:56 pm, Terry Reedy wrote: > J wrote: > > On Wed, Dec 2, 2009 at 09:27, nn wrote: > >>> Is there a way to read the file, one item at a time, delimited by > >>> commas WITHOUT having to read all 16,000 items from that one line, > >>>

Re: Question about file objects...

2009-12-02 Thread nn
On Dec 2, 9:14 am, J wrote: > Something that came up in class... > > when you are pulling data from a file using f.next(), the file is read > one line at a time. > > What was explained to us is that Python iterates the file based on a > carriage return as the delimiter. > But what if you have a fi

Re: Language mavens: Is there a programming with "if then else ENDIF" syntax?

2009-11-17 Thread nn
On Nov 16, 11:54 am, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python.  I like P

Re: A stupid newbie question about output...

2009-10-20 Thread nn
On Oct 20, 2:23 pm, J wrote: > Can someone explain why this code results in two different outputs? > > > for os in comp.CIM_OperatingSystem (): > >  print os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVersion > >  osVer = os.Name.split("|")[0] + " Service Pack", os.ServicePackMajorVe

Re: Why is this slower?

2009-10-06 Thread nn
On Oct 5, 12:46 pm, Joseph Reagle wrote: > I would think the commented code would be faster (fewer loops), but it is > not (because of function calls). > >     #Average user_time = 5.9975 over 4 iterations >     inSRC = set([bio.name for bio in bios.values()]) >     inEB = set([bio.name for bio in

Re: Enormous Input and Output Test

2009-10-05 Thread nn
On Oct 4, 8:41 am, Duncan Booth wrote: > Jon Clements wrote: > > On Oct 4, 12:08 pm, n00m wrote: > >> Duncan Booth, > > >> alas... still TLE: > > >> 2800839 > >> 2009-10-04 13:03:59 > >> Q > >> Enormous Input and Output Test > >> time limit exceeded > >> - > >> 88M > >> PYTH > > > Just to throw

Re: Using String for new List name

2009-09-29 Thread nn
On Sep 28, 7:37 pm, Scott wrote: > On Sep 28, 2:00 pm, Dave Angel wrote: > > > > > Scott wrote: > > > Thank you fine folks for getting back with your answers! > > > > So down the road I do dictname[line42].append("new stuff"). (or [var] > > > if I'm looping through the dict) > > > Nope, you still

Re: Poll: Do you use csv.Sniffer?

2009-09-25 Thread nn
On Sep 24, 10:26 pm, s...@pobox.com wrote: > If you are a csv module user, I have a question for you:  Do you use the > csv.Sniffer class? > >     o Yes, frequently >     o Yes, on occasion >     o I tried it a few times but don't use it now >     o No, I don't need it >     o No, never heard of it

Re: custom data warehouse in python vs. out-of-the-box ETL tool

2009-09-23 Thread nn
On Sep 22, 4:00 pm, snfctech wrote: > Does anyone have experience building a data warehouse in python?  Any > thoughts on custom vs using an out-of-the-box product like Talend or > Informatica? > > I have an integrated system Dashboard project that I was going to > build using cross-vendor joins o

Re: Extracting patterns after matching a regex

2009-09-08 Thread nn
On Sep 8, 12:16 pm, nn wrote: > On Sep 8, 11:19 am, Dave Angel wrote: > > > > > Mart. wrote: > > > > > > I have been doing this to turn the email into a string > > > > email =ys.argv[1] > > > f =open(email, 'r') > > >

Re: Extracting patterns after matching a regex

2009-09-08 Thread nn
On Sep 8, 11:19 am, Dave Angel wrote: > Mart. wrote: > > > > I have been doing this to turn the email into a string > > > email =ys.argv[1] > > f =open(email, 'r') > > s =str(f.readlines()) > > > so FTPHOST isn't the first element, it is just part of a larger > > string. When I turn the email int

Re: Extracting patterns after matching a regex

2009-09-08 Thread nn
On Sep 8, 10:25 am, "Mart." wrote: > On Sep 8, 3:21 pm, nn wrote: > > > > > On Sep 8, 9:55 am, "Mart." wrote: > > > > On Sep 8, 2:16 pm, "Andreas Tawn" wrote: > > > > > > Hi, > > > > > > I need to

Re: Extracting patterns after matching a regex

2009-09-08 Thread nn
On Sep 8, 10:27 am, pdpi wrote: > On Sep 8, 3:21 pm, nn wrote: > > > > > On Sep 8, 9:55 am, "Mart." wrote: > > > > On Sep 8, 2:16 pm, "Andreas Tawn" wrote: > > > > > > Hi, > > > > > > I need to extract a

  1   2   >