Re: using split for a string : error

2013-01-25 Thread Hans Mulder
On 25/01/13 15:04:02, Neil Cerutti wrote: > On 2013-01-25, Oscar Benjamin wrote: >> On 24 January 2013 11:35, Chris Angelico wrote: >>> It's usually fine to have int() complain about any >>> non-numerics in the string, but I must confess, I do sometimes >>> yearn for atoi() semantics: atoi("123as

Re: urllib2 FTP Weirdness

2013-01-23 Thread Hans Mulder
On 24/01/13 00:58:04, Chris Angelico wrote: > On Thu, Jan 24, 2013 at 7:07 AM, Nick Cash > wrote: >> Python 2.7.3 on linux >> >> This has me fairly stumped. It looks like >> urllib2.urlopen("ftp://some.ftp.site/path";).read() >> will either immediately return '' or hang indefinitely. But >

Re: please i need explanation

2013-01-11 Thread Hans Mulder
On 11/01/13 16:35:10, kwakukwat...@gmail.com wrote: > def factorial(n): > if n<2: > return 1 > f = 1 > while n>= 2: > f *= n > f -= 1 U think this line should have been: n -= 1 > return f Hope this helps, -- HansM -- http://mail.python.o

Re: help

2013-01-11 Thread Hans Mulder
On 10/01/13 19:35:40, kwakukwat...@gmail.com wrote: > pls this is a code to show the pay of two people.bt I want each of to be > able to get a different money when they enter their user name,and to use > it for about six people. > database = [ > ['Mac'], > ['Sam'], > ] > pay1 = 1000 > p

Re: Numpy outlier removal

2013-01-06 Thread Hans Mulder
On 6/01/13 20:44:08, Joseph L. Casale wrote: > I have a dataset that consists of a dict with text descriptions and values > that are integers. If > required, I collect the values into a list and create a numpy array running > it through a simple > routine: data[abs(data - mean(data)) < m * std(da

Re: Missing something obvious with python-requests

2013-01-04 Thread Hans Mulder
On 4/01/13 03:56:47, Chris Angelico wrote: > On Fri, Jan 4, 2013 at 5:53 AM, Ray Cote > wrote: >> proxies = { >> 'https': '192.168.24.25:8443', >> 'http': '192.168.24.25:8443', } >> >> a = requests.get('http://google.com/', proxies=proxies) >> >> >> When I look at the proxy log, I see a GE

Re: Question about nested loop

2012-12-31 Thread Hans Mulder
On 31/12/12 11:02:56, Isaac Won wrote: > Hi all, > I am a very novice for Python. Currently, I am trying to read continuous > columns repeatedly in the form of array. > my code is like below: > > import numpy as np > > b = [] > c = 4 > f = open("text.file", "r") > > while c < 10: > c =

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Hans Mulder
On 31/12/12 12:57:59, Adam Tauno Williams wrote: > On Thu, 2012-12-27 at 12:01 -0800, mogul wrote: >> 'Aloha! >> I'm new to python, got 10-20 years perl and C experience, all gained >> on unix alike machines hacking happily in vi, and later on in vim. >> Now it's python, and currently mainly on my

Re: Python lists

2012-12-30 Thread Hans Mulder
On 30/12/12 23:25:39, Evan Driscoll wrote: > On 12/30/2012 4:19 PM, Hans Mulder wrote: >> If it's okay to modify the original list, you can simply do: >> >> l[0] = split(l[0], ", ") >> >> If modifying the original is not okay, the simple solution wo

Re: Beginner: Trying to get REAL NUMBERS from %d command

2012-12-30 Thread Hans Mulder
Hello, Python does not support REAL numbers. It has float number, which are approximations of real numbers. They behave almost, but not quite, like you might expect. It also has Decimal numbers. They also approximate real numbers, but slightly differently. They might behave more like you'd ex

Re: Python lists

2012-12-30 Thread Hans Mulder
On 28/12/12 18:46:45, Alex wrote: > Manatee wrote: > >> On Friday, December 28, 2012 9:14:57 AM UTC-5, Manatee wrote: >>> I read in this: >>> >>> ['C100, C117', 'X7R 0.033uF 10% 25V 0603', '0603-C_L, 0603-C_N', >>> '10', '2', '', '30', '15463-333', 'MURATA', 'GRM188R71E333KA01D', >>> 'Digi-Key',

Re: Tarfile and usernames

2012-12-30 Thread Hans Mulder
On 30/12/12 19:57:31, Nicholas Cole wrote: > Dear List, > > I'm hoping to use the tarfile module in the standard library to move > some files between computers. > > I can't see documented anywhere what this library does with userids and > groupids. I can't guarantee that the computers involved

Re: need a url that its http response header that cotain 401 status code

2012-12-26 Thread Hans Mulder
On 26/12/12 10:08:41, iMath wrote: > I am going to do a Basic Authentication , > so I need a url > that its http response header that cotain 401 status code. Isn't that backwards? I mean, what's the point of implementing Basic Authentication, unless you already know a site that uses it? if yo

Re: Forking into the background (Linux)

2012-12-23 Thread Hans Mulder
On 24/12/12 01:50:24, Olive wrote: > My goal is to write a script that 1) write something to stdout; then > fork into the background, closing the stdout (and stderr, stdin) pipe. > > I have found this answer (forking -> setsid -> forking) > http://stackoverflow.com/a/3356154 > > However the stand

Re: how to detect the character encoding in a web page ?

2012-12-23 Thread Hans Mulder
On 24/12/12 01:34:47, iMath wrote: > how to detect the character encoding in a web page ? That depends on the site: different sites indicate their encoding differently. > such as this page: http://python.org/ If you download that page and look at the HTML code, you'll find a line: So it's

Re: redirect standard output problem

2012-12-21 Thread Hans Mulder
On 21/12/12 06:23:18, iMath wrote: > redirect standard output problem > > why the result only print A but leave out 888 ? > > import sys > class RedirectStdoutTo: > > def __init__(self, out_new): > self.out_new = out_new > def __enter__(self): > sys.stdout = self.out_new

Re: Build and runtime dependencies

2012-12-20 Thread Hans Mulder
On 20/12/12 23:11:45, Jack Silver wrote: > I have two Linux From Scratch machine. > > On the first one (the server), I want to build install python 3.3.0 in a > shared filesystem and access it from the second one (the client). These > machines are fairly minimal in term of the number of software i

Re: Strange effect with import

2012-12-20 Thread Hans Mulder
On 20/12/12 23:52:24, Jens Thoms Toerring wrote: > I'm writing a TCP server, based on SocketServer: > > server = SocketServer.TCPServer((192.168.1.10, 12345), ReqHandler) > > where ReqHandler is the name of a class derived from > SocketServer.BaseRequestHandler > > class ReqHandler(SocketServe

Re: Python3 + sqlite3: Where's the bug?

2012-12-20 Thread Hans Mulder
On 20/12/12 16:20:13, Johannes Bauer wrote: > On 20.12.2012 16:05, Chris Angelico wrote: >> On Fri, Dec 21, 2012 at 1:52 AM, Johannes Bauer wrote: >>> def fetchmanychks(cursor): >>> cursor.execute("SELECT id FROM foo;") >>> while True: >>> result = cursor.fetchmany(

Re: Why does os.stat() tell me that my file-group has no members?

2012-12-19 Thread Hans Mulder
On 19/12/12 22:40:00, saqib.ali...@gmail.com wrote: > > > I'm using python 2.6.4 on Solaris 5-10. > > I have a file named "myFile". It is owned by someone else, by > I ("myuser") am in the file's group ("mygrp"). Below is my python > code. Why does it tell me that mygrp has no members??? > > >

Re: Virtualenv loses context

2012-12-19 Thread Hans Mulder
On 19/12/12 15:38:01, rhythmicde...@gmail.com wrote: > Just installed a brand new virtualenv along with two packages. Ran this and I > got nothing: > > (venvtest)[swright@localhost venvtest]$ python -m site > (venvtest)[swright@localhost venvtest]$ > > I expected to have at least one path in sys

Re: Problem with Threads

2012-12-19 Thread Hans Mulder
On 19/12/12 18:11:37, Kwnstantinos Euaggelidis wrote: > I have this code for Prime Numbers and i want to do it with Threads.. > Any idea.?? Why would you want to do that? It's not going to be any faster, since your code is CPU-bound. You may have several CPUs, but CPython is going to use only one

Re: Why Doesn't This MySQL Statement Execute?

2012-12-18 Thread Hans Mulder
On 18/12/12 22:34:08, Tom Borkin wrote: > Hi; > I have this test code: > > if i_id == "1186": > sql = 'insert into interactions values(Null, %s, "Call Back", > "%s")' % (i_id, date_plus_2) > cursor.execute(sql) > db.commit() > print sql > It prints the sql statement, b

Re: os.system and subprocess odd behavior

2012-12-18 Thread Hans Mulder
On 17/12/12 21:56:50, py_genetic wrote: > /usr/local/Calpont/mysql/bin/mysql > --defaults-file=/usr/local/Calpont/mysql/my.cnf -u root myDB < > /home/myusr/jobs/APP_JOBS/JOB_XXX.SQL > /home/myusr/jobs/APP_JOBS/JOB_XXX.TXT If you're trying to interact with a MySQL database, then you should really

Re: os.system and subprocess odd behavior

2012-12-18 Thread Hans Mulder
On 18/12/12 11:39:56, Dave Angel wrote: > On 12/18/2012 05:27 AM, Hans Mulder wrote: >> On 18/12/12 06:10:43, photonym...@gmail.com wrote: >>> I hope I understand the question... but shouldn't you wait for the process >>> to complete before exiting? >

Re: Delete dict and subdict items of some name

2012-12-18 Thread Hans Mulder
On 18/12/12 06:30:48, Gnarlodious wrote: > This problem is solved, I am so proud of myself for figuring it out! > After reading some of these ideas I discovered the plist is really > lists underneath any "Children" key: > > > from plistlib import readPlist > > def explicate(listDicts): > f

Re: os.system and subprocess odd behavior

2012-12-18 Thread Hans Mulder
On 18/12/12 06:10:43, photonym...@gmail.com wrote: > I hope I understand the question... but shouldn't you wait for the process to > complete before exiting? > > Something like: > > pid = subprocess.Popen(...) > pid.wait() > > Otherwise, it'll exit before the background process is done. Why w

Re: Unicode

2012-12-17 Thread Hans Mulder
On 17/12/12 22:09:04, Dave Angel wrote: > print src.decode("utf-8").encode("latin-1", "ignore") > > That says to decode it using utf-8 (because the html declared a utf-8 > encoding), and encode it back to latin-1 (because your terminal is stuck > there), then print. > > > Just realize that once

Re: Running a python script under Linux

2012-12-14 Thread Hans Mulder
On 14/12/12 14:38:25, D'Arcy J.M. Cain wrote: > On Fri, 14 Dec 2012 14:18:28 +0100 > Hans Mulder wrote: >> The Pythonic way to get what you want, is to be explicit: >> >> #!/usr/local/bin/python2.7 -V >> >> If you do that, it will even work in situations

Re: Running a python script under Linux

2012-12-14 Thread Hans Mulder
On 14/12/12 03:45:18, Steven D'Aprano wrote: > I understand this is not exactly a Python question, but it may be of > interest to other Python programmers, so I'm asking it here instead of a > more generic Linux group. > > I have a Centos system which uses Python 2.4 as the system Python, so I

Re: regex walktrough

2012-12-08 Thread Hans Mulder
On 8/12/12 23:57:48, rh wrote: > Not sure if the \w sequence includes the - or the . or the / > I think it does not. You guessed right: >>> [ c for c in 'x-./y' if re.match(r'\w', c) ] ['x', 'y'] >>> So x and y match \w and -, . and / do not. Hope this helps, -- HansM -- http://mail.python

Re: regex walktrough

2012-12-08 Thread Hans Mulder
On 8/12/12 23:19:40, rh wrote: > I reduced the expression too. Now I wonder why re.DEBUG doesn't unroll > category_word. Some other re flag? he category word consists of the '_' character and the characters for which .isalnum() return True. On my system there are 102158 characters matching '\w':

Re: Issue with seeded map generation

2012-12-08 Thread Hans Mulder
On 8/12/12 22:32:22, Graham Fielding wrote: > Hey, all! > > I've managed to get my project to a semi-playable state (everything > functions, if not precisely the way I'd like it to). One small issue is > that when the player moves from one level to the next, the items and > monsters in the previ

Re: regex walktrough

2012-12-08 Thread Hans Mulder
On 8/12/12 18:48:13, rh wrote: > Look through some code I found this and wondered about what it does: > ^(?P[0-9A-Za-z-_.//]+)$ > > Here's my walk through: > > 1) ^ match at start of string > 2) ?P if a match is found it will be accessible in a > variable salsipuedes I wouldn't call it a variab

Re: python 3.3 urllib.request

2012-12-08 Thread Hans Mulder
On 8/12/12 07:20:55, Terry Reedy wrote: > On 12/7/2012 12:27 PM, Hans Mulder wrote: >> On 7/12/12 13:52:52, Steeve C wrote: >>> hello, >>> >>> I have a python3 script with urllib.request which have a stra

Re: python 3.3 urllib.request

2012-12-07 Thread Hans Mulder
On 7/12/12 13:52:52, Steeve C wrote: > hello, > > I have a python3 script with urllib.request which have a strange > behavior, here is the script : > > + > #!/usr/bin/env python3 > # -*- coding: utf-8 -*- > > import

Re: pyodbc utf-8

2012-12-07 Thread Hans Mulder
On 7/12/12 08:41:27, Markus Christen wrote: > good morning > > i am using pyodbc 3.0.6 for win32 python 2.7.3 > i used it to connect with a MsSql db. Now i have a little problem with the > umlaut. > i cant change anything in the db and there are umlauts like "ä", "ö" and "ü" saved. > so i have to

Re: Confused compare function :)

2012-12-06 Thread Hans Mulder
On 6/12/12 14:58:01, Chris Angelico wrote: > On Fri, Dec 7, 2012 at 12:33 AM, Thomas Rachel > > wrote: >> > Am 06.12.2012 09:49 schrieb Bruno Dupuis: >> > >>> >> The point is Exceptions are made for error handling, not for normal >>> >> workflow. I hate when i read that for example: >>> >> >>> >>

Re: Confused compare function :)

2012-12-06 Thread Hans Mulder
On 6/12/12 12:55:16, peter wrote: > Is perfectly right to use try catch for a flow control. > Just think in something more complex like this. > >try: > self._conn = MySQLdb.connect(host=host, > user=user, > passwd=passwd, > db=db) >

Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

2012-12-06 Thread Hans Mulder
On 6/12/12 11:07:51, iMath wrote: > the following code originally from > http://zetcode.com/databases/mysqlpythontutorial/ > within the "Writing images" part . > > > import MySQLdb as mdb > import sys > > try: > fin = open("Chrome_Logo.svg.png",'rb') > img = fin.read() > fin.close()

Re: Installing packages on Mac OS X 10.7.5

2012-12-05 Thread Hans Mulder
On 6/12/12 00:56:55, Irmen de Jong wrote: > On 6-12-2012 0:12, John Dildy wrote: >> I have python v2.7.1 and I am trying to install packages on the Mac OS X >> v10.7.5 >> I am trying to install: >> Distribute >> Nose >> virtualenv >> If anyone can help me that would be great > > Avoid changing st

Re: mini browser with python

2012-12-05 Thread Hans Mulder
On 5/12/12 22:44:21, inq1ltd wrote: > I can connect to and download a web page, > html code, and save it to a file. If connected > to the web, I can change the settings on KWrite > to open the file and navigate the page, > (just like a browser does). > I want to view the html file without using a

Re: mini browser with python

2012-12-05 Thread Hans Mulder
On 5/12/12 20:36:04, inq1ltd wrote: > Python help. ?This is not a Python question. > I can connect to and download a web page, > html code, and save it to a file. If connected > to the web, I can use KWrite to open the file > and navigate the page. > I want to view the html file without

Re: Conversion of List of Tuples

2012-12-04 Thread Hans Mulder
On 4/12/12 10:44:32, Alexander Blinne wrote: > Am 03.12.2012 20:58, schrieb subhabangal...@gmail.com: >> Dear Group, >> >> I have a tuple of list as, >> >> tup_list=[(1,2), (3,4)] >> Now if I want to covert as a simple list, >> >> list=[1,2,3,4] >> >> how may I do that? > > Another approach that h

Re: Weird exception handling behavior -- late evaluation in except clause

2012-12-02 Thread Hans Mulder
On 2/12/12 18:25:22, Roy Smith wrote: > This is kind of weird (Python 2.7.3): > > try: > print "hello" > except foo: > print "foo" > > prints "hello". The problem (IMHO) is that apparently the except clause > doesn't get evaluated until after some exception is caught. Which means > it

Re: Weird import failure with "nosetests --processes=1"

2012-11-29 Thread Hans Mulder
On 29/11/12 04:13:57, Roy Smith wrote: > I've got a minimal test script: > > - > $ cat test_foo.py > import pyza.models > print pyza.models > > def test_foo(): > pass > - > > pyza.models is a package. Under normal conditions, I can imp

Re: Getting a seeded value from a list

2012-11-26 Thread Hans Mulder
On 26/11/12 21:17:40, Prasad, Ramit wrote: > Chris Angelico wrote: >> >> On Sat, Nov 24, 2012 at 3:27 AM, Prasad, Ramit >> wrote: >>> Steven D'Aprano wrote: On Wed, 21 Nov 2012 14:41:24 +1100, Chris Angelico wrote: > However, this still means that the player will see the exact s

Re: How to pass class instance to a method?

2012-11-26 Thread Hans Mulder
On 27/11/12 00:07:10, Ian Kelly wrote: > On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel wrote: >> Not how I would put it. In a statically typed language, the valid types >> are directly implied by the function parameter declarations, > > As alluded to in my previous post, not all statically typed l

Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Hans Mulder
On 25/11/12 11:19:18, kobayashi wrote: > Hello, > > Under platform that has fixed pitch font, > I want to get a "screen" length of a multibyte string > > --- sample --- > s1 = u"abcdef" > s2 = u"あいう" # It has same "screen" length as s1's. > print len(s1) # Got 6 > print len(s2) # Got 3, but I w

Re: Print value from array

2012-11-23 Thread Hans Mulder
On 22/11/12 19:44:02, Mike wrote: > Hello, > I am noob en python programing, i wrote a perl script for read from csv but > now i wish print value but the value must be within double quote and I can > not do this. > > For example now the output is: > > ma user@domain displayName Name SecondNam

Re: mysql insert with tuple

2012-11-21 Thread Hans Mulder
On 21/11/12 18:19:15, Christian wrote: > Hi , > > my purpose is a generic insert via tuple , because the number of fields and > can differ. But I'm stucking . > > ilist=['hello',None,7,None,None] > > #This version works, but all varchar fields are in extra '' enclosed. > con.execute(""" INSER

Re: Inconsistent behaviour os str.find/str.index when providing optional parameters

2012-11-21 Thread Hans Mulder
On 21/11/12 17:59:05, Alister wrote: > On Wed, 21 Nov 2012 04:43:57 -0800, Giacomo Alzetta wrote: > >> I just came across this: >> > 'spam'.find('', 5) >> -1 >> >> >> Now, reading find's documentation: >> > print(str.find.__doc__) >> S.find(sub [,start [,end]]) -> int >> >> Return the lowe

Re: 10 sec poll - please reply!

2012-11-21 Thread Hans Mulder
On 21/11/12 02:17:26, Steven D'Aprano wrote: > On Tue, 20 Nov 2012 18:00:59 -0600, Tim Chase wrote: > >> On 11/20/12 06:18, Michael Herrmann wrote: >>> am having difficulty picking a name for the function that simulates key >>> strokes. I currently have it as 'type' but that clashes with the >>> b

Re: "Premature end of script headers: wsgihandler.py" on usage of BytesIO()

2012-11-19 Thread Hans Mulder
On 19/11/12 14:29:13, Yasir Saleem wrote: > Hi all, > > I am generating graphs using "cairo plot" in web2py project. > Here I am using BytesIO() stream for generating graphs. > Everything runs fine when I run on localhost but when I deploy > it on apache server and then run from different machines

Re: Unpaking Tuple

2012-11-18 Thread Hans Mulder
On 9/10/12 08:07:32, Bob Martin wrote: > in 682592 20121008 232126 "Prasad, Ramit" wrote: >> Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >> 03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >> tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if le

Re: Detect file is locked - windows

2012-11-14 Thread Hans Mulder
On 14/11/12 11:02:45, Tim Golden wrote: > On 14/11/2012 00:33, Ali Akhavan wrote: >> I am trying to open a file in 'w' mode open('file', 'wb'). open() >> will throw with IOError with errno 13 if the file is locked by >> another application or if user does not have permission to open/write >> to the

Re: Detect file is locked - windows

2012-11-14 Thread Hans Mulder
On 14/11/12 02:14:59, Mark Lawrence wrote: > On 14/11/2012 00:33, Ali Akhavan wrote: >> I am trying to open a file in 'w' mode open('file', 'wb'). open() will >> throw with IOError with errno 13 if the file is locked by another >> application or if user does not have permission to open/write to the

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-14 Thread Hans Mulder
On 13/11/12 22:36:47, Thomas Rachel wrote: > Am 12.11.2012 19:30 schrieb Hans Mulder: > >> This will break if there are spaces in the file name, or other >> characters meaningful to the shell. If you change if to >> >> xargsproc.append(

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Hans Mulder
On 12/11/12 18:22:44, jkn wrote: > Hi Hans > > On Nov 12, 4:36 pm, Hans Mulder wrote: >> On 12/11/12 16:36:58, jkn wrote: >> >> >> >> >> >> >> >> >> >>> slight followup ... >> >>> I have made some progre

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-12 Thread Hans Mulder
On 12/11/12 16:36:58, jkn wrote: > slight followup ... > > I have made some progress; for now I'm using subprocess.communicate to > read the output from the first subprocess, then writing it into the > secodn subprocess. This way I at least get to see what is > happening ... > > The reason 'we' w

Re: Obnoxious postings from Google Groups

2012-11-09 Thread Hans Mulder
On 7/11/12 01:13:47, Steven D'Aprano wrote: > On Tue, 06 Nov 2012 23:08:11 +, Prasad, Ramit wrote: > >> Steven D'Aprano wrote: >>> >>> On Tue, 06 Nov 2012 17:16:44 +, Prasad, Ramit wrote: >>> > To enter the newline, I typed Ctrl-Q to tell bash to treat the next > character as a lit

Re: Obnoxious postings from Google Groups

2012-11-09 Thread Hans Mulder
On 6/11/12 23:50:59, Steven D'Aprano wrote: > On Tue, 06 Nov 2012 17:16:44 +, Prasad, Ramit wrote: > >>> To enter the newline, I typed Ctrl-Q to tell bash to treat the next >>> character as a literal, and then typed Ctrl-J to get a newline. >> >> That sounds complicated, my version of bash let

Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?

2012-11-08 Thread Hans Mulder
On 8/11/12 19:05:11, jkn wrote: > Hi All > i am trying to build up a set of subprocess.Ponen calls to > replicate the effect of a horribly long shell command. I'm not clear > how I can do one part of this and wonder if anyone can advise. I'm on > Linux, fairly obviously. > > I have a command w

Re: Right solution to unicode error?

2012-11-08 Thread Hans Mulder
On 8/11/12 00:53:49, Steven D'Aprano wrote: > This error confuses me. Is that an exact copy and paste of the error, or > have you edited it or reconstructed it? Because it seems to me that if > task.subject is a unicode string, as it appears to be, calling print on > it should succeed: > > py>

Re: Base class and Derived class question

2012-11-06 Thread Hans Mulder
On 6/11/12 14:47:03, cyberira...@gmail.com wrote: > Hey guys, > I'm trying to understand how is working base class and derived class. > So, I have to files baseClass.py and derivedClass.py. > baseClass.py : > [CODE]class baseClass(): > def bFunction(self): > print "We are in a base cl

Re: Multi-dimensional list initialization

2012-11-05 Thread Hans Mulder
On 5/11/12 07:27:52, Demian Brecht wrote: > So, here I was thinking "oh, this is a nice, easy way to initialize a 4D > matrix" > (running 2.7.3, non-core libs not allowed): > > m = [[None] * 4] * 4 > > The way to get what I was after was: > > m = [[None] * 4, [None] * 4, [None] * 4, [None * 4]]

Re: is implemented with id ?

2012-11-04 Thread Hans Mulder
On 4/11/12 06:09:24, Aahz wrote: > In article , > Chris Angelico wrote: >> On Sun, Nov 4, 2012 at 2:10 PM, Steven D'Aprano >> wrote: >>> >>> /* Shortcut for empty or interned objects */ >>> if (v == u) { >>> Py_DECREF(u); >>> Py_DECREF(v); >>> return 0; >>> } >>> result = unicode_com

Re: is implemented with id ?

2012-11-03 Thread Hans Mulder
On 3/11/12 20:41:28, Aahz wrote: > [got some free time, catching up to threads two months old] > > In article <50475822$0$6867$e4fe5...@news2.news.xs4all.nl>, > Hans Mulder wrote: >> On 5/09/12 15:19:47, Franck Ditter wrote: >>> >>> - I should have

Re: csv read clean up and write out to csv

2012-11-02 Thread Hans Mulder
On 2/11/12 18:25:09, Sacha Rook wrote: > I have a problem with a csv file from a supplier, so they export data to csv > however the last column in the record is a description which is marked up > with html. > > trying to automate the processing of this csv to upload elsewhere in a > useable format

Re: sort order for strings of digits

2012-10-31 Thread Hans Mulder
On 31/10/12 16:17:14, djc wrote: > Python 3.2.3 (default, Oct 19 2012, 19:53:16) > sorted(n+s) > ['1', '10', '101', '13', '1a', '2', '2000', '222 bb', '3', '31', '40', > 'a', 'a1', 'ab', 'acd', 'b a 4', 'bcd'] > sorted(int(x) if x.isdigit() else x for x in n+s) > Traceback (most recent

Re: Error compiling python3.2.3: architecture of input file is incompatible

2012-10-27 Thread Hans Mulder
On 27/10/12 16:11:48, Tobias Marquardt wrote: > Hello, > > I am trying to compile Python 3.2.3. > On my 64 bit Ubuntu machine I have no problems but using Ubuntu 32 but I > get the following error: > > /usr/bin/ld: i386:x86-64 architecture of input file > `Parser/tokenizer_pgen.o' is incompatible

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Hans Mulder
On 24/10/12 14:51:30, andrea crotti wrote: > So I would like to be able to ask for confirmation when I receive a C-c, > and continue if the answer is "N/n". > > I'm already using an exception handler set with sys.excepthook, but I > can't make it work with the confirm_exit, because it's going to q

Re: 'generator ignored GeneratorExit''

2012-10-20 Thread Hans Mulder
On 21/10/12 01:41:37, Charles Hixson wrote: > On 10/20/2012 04:28 PM, Ian Kelly wrote: >> On Sat, Oct 20, 2012 at 2:03 PM, Charles Hixson >> wrote: >>> If I run the following code in the same module, it works correctly, >>> but if I >>> import it I get the message: >>> Exception RuntimeError: 'ge

Re: error executing "import html.parser" from a script

2012-10-19 Thread Hans Mulder
On 19/10/12 11:15:45, Paul Volkov wrote: > What is this madness? That's because your script is called "html.py". If you import html.parser, Python first imports html, then checks that it's a package and contains a module named "parser". When Python imports html, it searches for a file named "htm

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Hans Mulder
On 18/10/12 08:31:51, Steven D'Aprano wrote: > On Thu, 18 Oct 2012 02:06:19 -0400, Zero Piraeus wrote: >> 3. Say "well, at least it's not a backslash" and break the line using >> > parentheses. > I mostly do this. Since most lines include a bracket of some sort, I > rarely need to add outer parent

Re: Index in a list

2012-10-17 Thread Hans Mulder
On 17/10/12 12:10:56, Anatoli Hristov wrote: > I'm trying to index a text in a list as I'm importing a log file and > each line is a list. > > What I'm trying to do is find the right line which contains the text > User : and take the username right after the text "User :", but the > list.index("(U

Re: bad httplib latency due to IPv6 use

2012-10-17 Thread Hans Mulder
On 17/10/12 09:55:13, Ulrich Eckhardt wrote: > Hi! > > I noticed yesterday that a single HTTP request to localhost takes > roughly 1s, regardless of the actually served data, which is way too > long. After some digging, I found that the problem lies in > socket.create_connection(), which first tri

Re: list comprehension question

2012-10-17 Thread Hans Mulder
On 17/10/12 09:13:57, rusi wrote: > On Oct 17, 10:22 am, Terry Reedy wrote: >> On 10/16/2012 9:54 PM, Kevin Anthony wrote: >> >>> I've been teaching myself list comprehension, and i've run across >>> something i'm not able to convert. >> >> list comprehensions specifically abbreviate the code that

Re: cx_Oracle clause IN using a variable

2012-10-16 Thread Hans Mulder
On 16/10/12 15:41:58, Beppe wrote: > Hi all, > I don't know if it is the correct place to set this question, however, > I'm using cx_Oracle to query an Oracle database. > I've a problem to use the IN clause with a variable. > My statement is > > sql = "SELECT field1,field2,field3 > FROM m

Re: Insert item before each element of a list

2012-10-11 Thread Hans Mulder
On 9/10/12 04:39:28, rusi wrote: > On Oct 9, 7:34 am, rusi wrote: >> How about a 2-paren version? >> > x = [1,2,3] > reduce(operator.add, [['insert', a] for a in x]) >> >> ['insert', 1, 'insert', 2, 'insert', 3] > > Or if one prefers the different parens on the other side: > reduce

Re: error bluetooth

2012-10-05 Thread Hans Mulder
On 5/10/12 10:51:42, Luca Sanna wrote: > from bluetooth import * [..] > luca@luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py When you say "from bluetooth import *", Python will find a file name "bluetooth.py" and import stuff from that file. Since your script happens to

Re: How to create a login screen using core python language without using any framework

2012-10-05 Thread Hans Mulder
On 5/10/12 10:03:56, shivakrsh...@gmail.com wrote: > I need to develop a simple login page using Python language with > two fields and a button, like: > > Username, Password, Login > > I know there are some beautiful Python frameworks like > > Django, Grok, WebPy, TurboGears > > which su

Re: Can somebody give me an advice about what to learn?

2012-10-03 Thread Hans Mulder
On 1/10/12 00:14:29, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> you can't, for instance, retain a "socket connection object" across >> that sort of reload. > > Yeah, that's a problem. There's nothing fundamental about a TCP > connection endpoint which precludes it being ser

Re: parse an environment file

2012-10-01 Thread Hans Mulder
On 1/10/12 16:12:50, Jason Friedman wrote: >> I want my python 3.2.2 script, called via cron, to know what those >> additional variables are. How? > > Thank you for the feedback. A crontab line of > > * * * * * . /path/to/export_file && /path/to/script.py > > does indeed work, but for various

Re: Can't import modules

2012-09-30 Thread Hans Mulder
On 30/09/12 21:42:37, Peter Farrell wrote: > I'm still new to Python, so here's another easy one. After I save something > I've done as a .py file, how do I import it into something else I work on? > Every time I try to import something other than turtle or math, I get this > error message: > > '

Re: [Python-Dev] [RELEASED] Python 3.3.0

2012-09-29 Thread Hans Mulder
On 29/09/12 14:23:49, Amit Saha wrote: > On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: >> On behalf of the Python development team, I'm delighted to announce the >> Python 3.3.0 final release. Thank you!!! >> For a more extensive list of changes in 3.3.0, see >> >> http://docs.pytho

Re: howto handle nested for

2012-09-29 Thread Hans Mulder
On 29/09/12 03:15:24, Peter Pearson wrote: > On Fri, 28 Sep 2012 09:49:36 -0600, Ian Kelly wrote: >> >> levels = 6 >> for combination in itertools.product(xrange(n_syms), levels): >> # do stuff > n_syms = 3 levels = 6 for combination in itertools.product(xrange(n_syms), levels)

Re: Reducing cache/buffer for faster display

2012-09-29 Thread Hans Mulder
On 29/09/12 02:20:50, Rikishi42 wrote: > On 2012-09-28, Dennis Lee Bieber wrote: >> On Thu, 27 Sep 2012 22:25:39 + (UTC), John Gordon >> declaimed the following in gmane.comp.python.general: >> >>> >>> Isn't terminal output line-buffered? I don't understand why there would >>> be an output d

Re: Need to archive a MySQL database using a python script

2012-09-26 Thread Hans Mulder
On 26/09/12 01:17:24, bruceg113...@gmail.com wrote: > Python Users Group, > > I need to archive a MySQL database using a python script. > I found a good example at: https://gist.github.com/3175221 > > The following line executes however, the archive file is empty. > > os.popen("mysqldump -u %s -

Re: Exact integer-valued floats

2012-09-23 Thread Hans Mulder
On 23/09/12 01:06:08, Dave Angel wrote: > On 09/22/2012 05:05 PM, Tim Roberts wrote: >> Dennis Lee Bieber wrote: >>> On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: For non IEEE 754 floating point systems, there is no telling how bad the implementation could be :( >>> Let's see

Re: Redirecting STDOUT to a Python Variable

2012-09-23 Thread Hans Mulder
On 22/09/12 23:57:52, ross.mars...@gmail.com wrote: > To capture the traceback, so to put it in a log, I use this > > import traceback > > def get_traceback(): # obtain and return the traceback > exc_type, exc_value, exc_traceback = sys.exc_info() > return ''.join(traceback.format_excepti

Re: how to do draw pattern with python?

2012-09-22 Thread Hans Mulder
On 21/09/12 19:32:20, Ian Kelly wrote: > On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farfán wrote: >> 2012/9/21 Peter Otten <__pete...@web.de>: >>> echo.hp...@gmail.com wrote: >>> >>> print "\x1b[2J\x1b[0;0H" # optional >> >> Nice code : ) >> >> Could you dissect that weird string for us? >> >> I

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-22 Thread Hans Mulder
On 22/09/12 09:30:57, Franck Ditter wrote: > In article <505ccdc5$0$6919$e4fe5...@news2.news.xs4all.nl>, > Hans Mulder wrote: > >> On 21/09/12 16:29:55, Franck Ditter wrote: >>> I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). >>>

Re: Exact integer-valued floats

2012-09-21 Thread Hans Mulder
On 21/09/12 22:26:26, Dennis Lee Bieber wrote: > On 21 Sep 2012 17:29:13 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > >> >> The question is, what is the largest integer number N such that every >> whole number between -N and N inclusive can be represented as a

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-21 Thread Hans Mulder
On 21/09/12 16:29:55, Franck Ditter wrote: > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > It runs fine and creates the disk file, visible with > TextWrangler or another. > But I can't open it with IDLE (its name is greyed). > IDLE is supposed to read utf-8 files, no ? > Th

Re: portable way of locating an executable (like which)

2012-09-21 Thread Hans Mulder
On 21/09/12 04:31:17, Dave Angel wrote: > On 09/20/2012 06:04 PM, Jason Swails wrote: >> On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N wrote: >> >>> I'd like to implement the equivalent functionality of the unix command >>> /usr/bin/which >>> >>> The function should work under Linux and under window

Re: How to get the list of all my open file(descriptor)s and locks?

2012-09-20 Thread Hans Mulder
On 20/09/12 05:11:11, Chris Angelico wrote: > On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly wrote: >> You could do: >> >> os.listdir("/proc/%d/fd" % os.getpid()) >> >> This should work on Linux, AIX, and Solaris, but obviously not on Windows. On MacOS X, you can use os.listdir("/dev/fd") This

Re: Installing Pip onto a mac os x system

2012-09-20 Thread Hans Mulder
On 20/09/12 03:32:40, John Mordecai Dildy wrote: > Does anyone know how to install Pip onto a mac os x ver 10.7.4? > > Ive tried easy_instal pip but it brings up this message (but it doesn't help > with my problem): > > error: can't create or remove files in install directory > > The following

Re: sum works in sequences (Python 3)

2012-09-19 Thread Hans Mulder
On 19/09/12 17:07:04, Alister wrote: > On Wed, 19 Sep 2012 16:41:20 +0200, Franck Ditter wrote: > >> Hello, >> I wonder why sum does not work on the string sequence in Python 3 : >> > sum((8,5,9,3)) >> 25 > sum([5,8,3,9,2]) >> 27 > sum('rtarze') >> TypeError: unsupported operand type(s

Re: 'indent'ing Python in windows bat

2012-09-19 Thread Hans Mulder
On 19/09/12 19:51:44, Albert Hopkins wrote: > On Tue, 2012-09-18 at 22:12 -0600, Jason Friedman wrote: >>> I'm converting windows bat files little by little to Python 3 as I find time >>> and learn Python. >>> The most efficient method for some lines is to call Python like: >>> python -c "import sy

  1   2   3   >