Re: Ordering in the printout of a dictionary

2014-03-18 Thread Marc Christiansen
Chris Angelico wrote: > On Tue, Mar 18, 2014 at 11:32 AM, Mok-Kong Shen > wrote: >> Is there a way to force a certain ordering of the printout or else >> somehow manage to get at least a certain stable ordering of the >> printout (i.e. input and output are identical)? > > Yes; instead of simply

Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno wrote: > >> From: usenetm...@solar-empire.de > [...] >> Not in Python3.x > decks = 6 > list(range(13 * 4 * decks)) == range(13 * 4 * decks) >> False > > What does "list(range(13 * 4 * decks))" returns in Python 3?

Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno wrote: > >> Date: Sun, 26 May 2013 10:52:14 -0700 >> Subject: Cutting a deck of cards >> From: rvinc...@gmail.com >> To: python-list@python.org >> >> Suppose I have a deck of cards, and I shuffle them >> >> import random >> cards = [] >> d

Re: CrazyHTTPd - HTTP Daemon in Python

2013-05-26 Thread Marc Christiansen
Mark Lawrence wrote: > On 26/05/2013 04:55, cdorm...@gmail.com wrote: >> This is a small little Project that I have started. Its a light >> little Web Server (HTTPd) coded in python. Requirements: Python 2.7 >> =< And Linux / BSD. I believe this could work in a CLI Emulator in >> windows too. >> W

Re: Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Marc Christiansen
Terry Reedy wrote: > On 2/12/2013 7:47 AM, Fayaz Yusuf Khan wrote: >> dcomp = zlib.decompressobj(16+zlib.MAX_WBITS) > > Since zlib.MAX_WBITS is the largest value that should be passed (15), > adding 16 makes no sense. Since it is also the default, there is also no > point in providing it explic

Re: strptime - dates formatted differently on different computers

2012-12-11 Thread Marc Christiansen
Greg Donald wrote: > On Mon, Dec 10, 2012 at 10:34:31PM -0700, Michael Torrie wrote: >> I use a module I got from pypi called dateutil. It has a nice submodule >> called parser that can handle a variety of date formats with good >> accuracy. Not sure how it works, but it handles all the common A

Re: numpy.genfromtxt with Python3 - howto

2012-04-06 Thread Marc Christiansen
Helmut Jarausch wrote: > I have a machine with a non-UTF8 local. > I can't figure out how to make numpy.genfromtxt work [...] > #!/usr/bin/python3 > import numpy as np > import io > import sys > > inpstream = io.open(sys.stdin.fileno(), "r", encoding='latin1') > > data = np.genfromtxt(inpstream)

Re: ERROR:root:code for hash md5 was not found

2012-01-14 Thread Marc Christiansen
Steven D'Aprano wrote: > On Fri, 13 Jan 2012 06:14:50 -0800, mike wrote: >> pysibelius is a lib that we use. >> >> I am not sure that is the problem since the python program works on SuSE >> but not on RH server. And AFAIK >> the only difference ( well that I can see) is the OpenSSL version. > >

Re: Can't I define a decorator in a separate file and import it?

2011-12-22 Thread Marc Christiansen
Saqib Ali wrote: > I'm using this decorator to implement singleton class in python: > > http://stackoverflow.com/posts/7346105/revisions > > The strategy described above works if and only if the Singleton is > declared and defined in the same file. If it is defined in a different > file and I im

Re: How to insert my own module in front of site eggs?

2011-11-17 Thread Marc Christiansen
Roy Smith wrote: > I'm trying to use a custom version of mongoengine. I cloned the git > repo and put the directory on my PYTHONPATH, but python is still > importing the system's installed version. Looking at sys.path, it's > obvious why: > > $ echo $PYTHONPATH > /home/roy/songza:/home/roy/

Re: PREFIX directory for pip command

2011-11-15 Thread Marc Christiansen
Makoto Kuwata wrote: > Is it possible to specify PREFIX directory for pip command by > environment variable? > > I found that 'pip install --install-option=--prefix=PREFIX' works well, > but I don't want to specify '--install-option=--prefix=PREFIX' every time. > I prefer to specify it by environ

Re: pairwise combination of two lists

2011-08-17 Thread Marc Christiansen
Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. Depending on

Re: GIL in alternative implementations

2011-05-28 Thread Marc Christiansen
Daniel Kluev wrote: > test.py: > > from threading import Thread > class X(object): >pass > obj = X() > obj.x = 0 > > def f(*args): > for i in range(1): > obj.x += 1 > > threads = [] > for i in range(100): >t = Thread(target=f) >threads.append(t) >t.start() > > for t

Re: Python 3 encoding question: Read a filename from stdin, subsequently?open that filename

2010-11-30 Thread Marc Christiansen
Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. Irrespective of how filenames are > encoded, thin

Re: strange problem with multiprocessing

2010-11-11 Thread Marc Christiansen
Neal Becker wrote: > Any idea what this could be about? > > Traceback (most recent call last): > File "run-tests-1004.py", line 48, in >results = pool.map (run_test, cases) > File "/usr/lib64/python2.7/multiprocessing/pool.py", line 199, in map >return self.map_async(func, iterable

Re: Factory for Struct-like classes

2008-08-13 Thread Marc Christiansen
eliben <[EMAIL PROTECTED]> wrote: > Hello, > > I want to be able to do something like this: > > Employee = Struct(name, salary) > > And then: > > john = Employee('john doe', 34000) > print john.salary > > Basically, Employee = Struct(name, salary) should be equivalent to: > > class Employee(o

Re: Swap memory in Python ? - three questions

2008-07-29 Thread Marc Christiansen
Robert LaMarca <[EMAIL PROTECTED]> wrote: > Hi, > > I am using numpy and wish to create very large arrays. My system is > AMD 64 x 2 Ubuntu 8.04. Ubuntu should be 64 bit. I have 3gb RAM and a > 15 GB swap drive. > > The command I have been trying to use is; > g=numpy.ones([1000,1000,1000],

Re: Testing for Internet Connection

2008-07-15 Thread Marc Christiansen
Alex Marandon <[EMAIL PROTECTED]> wrote: > Alexnb wrote: >> I am wondering, is there a simple way to test for Internet connection? If >> not, what is the hard way :p > > Trying to fetch the homepage from a few major websites (Yahoo, Google, > etc.)? If all of them are failing, it's very likely th

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-12 Thread Marc Christiansen
ssecorp <[EMAIL PROTECTED]> asked: > Why is this blowing the stack, thought it was tail-recursive... Because python does no tail-call optimization. Ciao Marc -- http://mail.python.org/mailman/listinfo/python-list

Re: Producing multiple items in a list comprehension

2008-05-22 Thread Marc Christiansen
Joel Koltner <[EMAIL PROTECTED]> wrote: > Is there an easy way to get a list comprehension to produce a flat > list of, say, [x,2*x] for each input argument? > > E.g., I'd like to do something like: > > [ [x,2*x] for x in range(4) ] > > ...and receive > > [ 0,0,1,2,2,4,3,6] > > ...but of cours

Re: Bug in floating-point addition: is anyone else seeing this?

2008-05-21 Thread Marc Christiansen
Mark Dickinson <[EMAIL PROTECTED]> wrote: > On SuSE 10.2/Xeon there seems to be a rounding bug for > floating-point addition: > > [EMAIL PROTECTED]:~> python > Python 2.5 (r25:51908, May 25 2007, 16:14:04) > [GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2 > Type "help", "copyright", "cred

Re: Compress a string

2008-05-18 Thread Marc Christiansen
Matt Porter <[EMAIL PROTECTED]> wrote: > Hi guys, > > I'm trying to compress a string. > E.g: > "BBBC" -> "ABC" You mean like this? >>> ''.join(c for c, _ in itertools.groupby("BBBCAADCASS")) 'ABCADCAS' HTH Marc -- http://mail.python.org/mailman/listinfo/python-list

Re: confused about self, why not a reserved word?

2008-05-05 Thread Marc Christiansen
globalrev <[EMAIL PROTECTED]> wrote: > class Foo(object): >def Hello(self): >print "hi" > > object is purple, ie some sort of reserved word. > > why is self in black(ie a normal word) when it has special powers. Because `self` is just a name. Using `self` is a convention,

Re: is +=1 thread safe

2008-05-04 Thread Marc Christiansen
Alexander Schmolck <[EMAIL PROTECTED]> wrote: > Gary Herron <[EMAIL PROTECTED]> writes: > >> But... It's not! >> >> A simple test shows that. I've attached a tiny test program that >> shows this extremely clearly. Please run it and watch it fail. > > In [7]: run ~/tmp/t.py > final count: 200

Re: xml.dom.minidom weirdness: bug?

2008-04-30 Thread Marc Christiansen
JYA <[EMAIL PROTECTED]> wrote: >for y in x.getElementsByTagName('display-name'): >elem.appendChild(y) Like Gabriel wrote, nodes can only have one parent. Use elem.appendChild(y.cloneNode(True)) instead. Or y.cloneNode(False), if you want a shallow copy (i

Re: Get all strings matching given RegExp

2008-04-03 Thread Marc Christiansen
Alex9968 <[EMAIL PROTECTED]> wrote: > Can I get sequence of all strings that can match a given regular > expression? For example, for expression '(a|b)|(x|y)' it would be ['ax', > 'ay', 'bx', 'by'] > > It would be useful for example to pass these strings to a search engine > not supporting RegE

Re: Interesting math problem

2008-03-18 Thread Marc Christiansen
sturlamolden <[EMAIL PROTECTED]> wrote: > On 18 Mar, 00:58, Jeff Schwab <[EMAIL PROTECTED]> wrote: > >> def make_slope(distance, parts): >> if parts == 0: >> return [] >> >> q, r = divmod(distance, parts) >> >> if r and parts % r: >> q += 1 >> >> return [q] +

Re: Unicode/UTF-8 confusion

2008-03-15 Thread Marc Christiansen
Tom Stambaugh <[EMAIL PROTECTED]> wrote: >> Somehow I don't get what you are after. The ' doesn't have to be escaped >> at all if " are used to delimit the string. If ' are used as delimiters >> then \' is a correct escaping. What is the problem with that!? > > If I delimit the string with doub

Re: tcp client socket bind problem

2008-03-10 Thread Marc Christiansen
[EMAIL PROTECTED] wrote: > I have a linux box with multiple ip addresses. I want to make my > python client connect from one of the ip addresses. Here is my code, > no matter what valid information I put in the bind it always comes > from the default ip address on the server. Am I doing something w

Re: unicode box drawing

2008-03-04 Thread Marc Christiansen
jefm <[EMAIL PROTECTED]> wrote: > How can I print the unicode box drawing characters in python: > > > print u'\u2500' > print u'\u2501' > print u'\u2502' > print u'\u2503' > print u'\u2504' > > Traceback (most recent call last): > File "\test.py", line 3, in ? >print u'\u2500' > File "C:\P

Re: Code Management

2007-12-07 Thread Marc Christiansen
BlueBird <[EMAIL PROTECTED]> wrote: > On Dec 2, 4:27 pm, BlueBird <[EMAIL PROTECTED]> wrote: >> On Nov 26, 5:07 pm, "Sergio Correia" <[EMAIL PROTECTED]> wrote: >> >> >Bluebird: >> >> > If you are using python 2.5, relative imports are no longer an >> > issue:http://docs.python.org/whatsnew/pep-328.

Re: JSON

2007-12-06 Thread Marc Christiansen
Joshua Kugler <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> i tried a couple python json libraries. i used simplejson on the >> server and was using cjson on the client, but i ran into this issue. >> i'm now using simplejson on both sides, but i'm still interested in >> this issue. d

Re: Some clauses cases BeautifulSoup to choke?

2007-11-20 Thread Marc Christiansen
gt; > http://www.naco.faa.gov/digital_tpp_search.asp?fldIdent=ksfo&fld_ident_type=ICAO&ver=0711&bnSubmit=Complete+Search > > > > Marc Christiansen <[EMAIL PROTECTED]> wrote: > >> The problem is this line: >> >> >> Which is wrong. The content is

Re: Some clauses cases BeautifulSoup to choke?

2007-11-19 Thread Marc Christiansen
Frank Stutzman <[EMAIL PROTECTED]> wrote: > I've got a simple script that looks like (watch the wrap): > --- > import BeautifulSoup,urllib > > ifile = urllib.urlopen("http://www.naco.faa.gov/digital_tpp_search.asp?fldId > ent=klax&fld_ident_type=ICAO

Re: class='something' as kwarg

2007-11-17 Thread Marc Christiansen
Vladimir Rusinov <[EMAIL PROTECTED]> wrote: > I'm using beautiful soup html parser, and I need to get all ' class=g>...' tags. > It can be done by: > > import BeautifulSoup as BSoup from BeautifulSoup import BeautifulSoup as BSoup > > ... > > soup = BSoup(page) > for div in soup.findAll('div',

Re: tinyp2p - trying to get it to work

2007-10-07 Thread Marc Christiansen
Fantus <[EMAIL PROTECTED]> wrote: > Hello > > I am doing a small research and I found this: > > http://www.freedom-to-tinker.com/tinyp2p.html [...] > Now when I try to run a client using following command: > > > python tinyp2p.py haslo client http://10.10.10.1:2233 koniki > > it gives me some s

Re: True of False

2007-09-27 Thread Marc Christiansen
Casey <[EMAIL PROTECTED]> wrote: > I would recommend the OP try this: > > run the (I)python shell and try the following: > a = [x for x in "abcdefg"] a > ['a','b','c','d','e','f','g'] "c" in a > True "c" in a == True > False ("c" in a) == True > True > > The reason your

Re: os.removedirs - How to force this delete?

2007-09-27 Thread Marc Christiansen
[EMAIL PROTECTED] wrote: > I've been searching to find a way to force this delete to work even if > the directory isn't empty. I've had no luck thus far. Anyone know > what that would be? Answering your immediate question: you can't force os.removedirs to delete non-empty dirs. But shutil.rmtree

Re: Type of __builtins__ changes from module import to execution?

2007-06-22 Thread Marc Christiansen
Adam Hupp <[EMAIL PROTECTED]> wrote: > I've noticed some unexpected behavior with __builtins__ during module > import. It seems that during module import __builtins__ is a dict > but at all other times it is a module. > > For example, if the file testmod.py has these contents: > > print type(__

Re: Floating Number format problem

2007-06-12 Thread Marc Christiansen
Peter Otten <[EMAIL PROTECTED]> wrote: > Marc Christiansen wrote: > >> Gabriel Genellina <[EMAIL PROTECTED]> wrote: >>> En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió: >>> >>>> On 6 12 , 3 16 , ici <[EMAIL PROTEC

Re: Accessing attributes

2007-06-12 Thread Marc Christiansen
Jeff Rollin <[EMAIL PROTECTED]> wrote: > I'm working with the Python Tutorial "Byte of Python" at swaroopch.info. > > I have created the attached file, but when I execute: > > % objvar.py > > I get the error message: > > (Initializing Calamity Jane) > Traceback (most recent call last): > File

Re: Floating Number format problem

2007-06-12 Thread Marc Christiansen
Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió: > >> On 6 12 , 3 16 , ici <[EMAIL PROTECTED]> wrote: >>> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote: >>> >>> > How could I format the float number like this: (keep

Re: __dict__ for instances?

2007-05-13 Thread Marc Christiansen
Ivan Voras <[EMAIL PROTECTED]> scribis: > While using PyGTK, I want to try and define signal handlers > automagically, without explicitly writing the long dictionary (i.e. I > want to use signal_autoconnect()). > > To do this, I need something that will inspect the current "self" and > return a di

Re: Minor bug in tempfile module (possibly __doc__ error)

2007-05-10 Thread Marc Christiansen
James T. Dennis <[EMAIL PROTECTED]> scribis: > In fact I realized, after reading through tempfile.py in /usr/lib/... > that the following also doesn't "work" like I'd expect: > ># foo.py >tst = "foo" >def getTst(arg): If I change this line: >return "foo-%s"

Re: decimal and trunkating

2005-06-02 Thread Marc Christiansen
Timothy Smith <[EMAIL PROTECTED]> wrote: > i want to trunkate 199.999 to 199.99 > getcontext.prec = 2 isn't what i'm after either, all that does is E's > the value. > do i really have to use floats to do this? You could try this (from a script I use for my phone bill): from decimal import Decima

Re: Best way to make a list unique?

2005-03-09 Thread Marc Christiansen
Michael Spencer <[EMAIL PROTECTED]> wrote: Nice. When you replace None by an object(), you have no restriction on the elements any more: > Here's something to work with: > > class OrdSet(object): > def __init__(self, iterable): > """Build an ordered, unique collection of hashable ite

Re: Finding user's home dir

2005-02-03 Thread Marc Christiansen
Miki Tebeka <[EMAIL PROTECTED]> wrote: > Hello Nemesis, > >> Hi all, I'm trying to write a multiplatform function that tries to >> return the actual user home directory. >> ... > What's wrong with: >from user import home > which does about what your code does. Except it also execfile()s $HOME

Re: test_socket.py failure

2005-02-02 Thread Marc Christiansen
[EMAIL PROTECTED] wrote: > Nick Coghlan <[EMAIL PROTECTED]> wrote: >> Hmm, when the second argument is omitted, the system call looks like: >> >> getservbyname("daytime", NULL); >> >> Based on "man getservbyname" on my Linux PC, that should give >> the behaviour we >> want - any protocol will ma

Re: cookie lib policy how-tp?

2004-12-08 Thread Marc Christiansen
Riko Wichmann <[EMAIL PROTECTED]> wrote: >>>Tried that already. At least, I hope I guessed at least one of the >>>possible identifiers correct: MSIE6.0, MSIE 6.0, MSIE/6.0 >> >> >> When my opera is set to identify as MSIE, it sends >> "Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera 7

Re: cookie lib policy how-tp?

2004-12-07 Thread Marc Christiansen
Riko Wichmann <[EMAIL PROTECTED]> wrote: > Jonathan Ellis wrote: >> >> Sounds like your first step should be to identify yourself as IE. >> >> opener = urllib2.build_opener(...) >> opener.addheaders = [("User-Agent", "whatever IE calls itself these >> days")] >> >> -Jonathan >> > > Tried that