Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-28 Thread Roy Smith
In article <34va6856ocuas7jpueujscf3kdt7k44...@4ax.com>, Gilles wrote: > Hello > > I've seen both shebang lines to run a Python script on a *nix host: > > #!/usr/bin/env python > #!/usr/bin/python > > What's the difference? The first one looks through your PATH to find the right python inte

Re: creating an artificial "last element" in sort list

2012-09-28 Thread duncan smith
On 29/09/12 00:51, dave wrote: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zz', 'zz', 'zz'] and the quantity of ''zz'' would be dynamic. Maybe, class Greatest: def __lt__(self, other): r

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

2012-09-30 Thread Roy Smith
In article , Chris Angelico wrote: > there's no efficient and reliable way to change/reload code in a > running application (not often an issue). What we do (largely cribbed from django's runserver) is start up a thread which once a second, looks at all the modules in sys.modules, checks to

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

2012-09-30 Thread Roy Smith
In article , Chris Angelico wrote: > On Mon, Oct 1, 2012 at 12:23 AM, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> there's no efficient and reliable way to change/reload code in a > >> running application (not often an issu

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

2012-09-30 Thread Roy Smith
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 serialized and passed around. The amount of state inv

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

2012-09-30 Thread Roy Smith
In article <4806a0b7-818a-4844-8286-f1b891a3c...@rj6g2000pbc.googlegroups.com>, rusi wrote: > Here's a test to help you decide: How do you respond to the word > 'magic'? If positive you will like Ruby, if not you may prefer > Python. Some might say that magic underscores a lot of the really

Re: unit testing class hierarchies

2012-10-02 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > >> Another is to remove it from the global namespace with > >> > >> del TestBase When I had this problem, that's the solution I used. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unpaking Tuple

2012-10-06 Thread Roy Smith
In article , Chris Rebert wrote: > But at any rate: > shortfall = 4 - len(your_tuple) > your_tuple += (None,) * shortfall # assuming None is a suitable default > a, b, c, d = your_tuple > > If you also need to handle the "too many items" case, use slicing: > a, b, c, d = your_tuple[:4] I usual

Re: getting the state of an object

2012-10-07 Thread Roy Smith
In article <507170e9$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > I've just looked at one of my classes, picked randomly, and the largest > method is twelve lines, the second largest is eight, and the average is > three lines. I took a look at a subtree of the project

Re: Insert item before each element of a list

2012-10-08 Thread Roy Smith
In article , Terry Reedy wrote: > On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote: > > What's the best way to accomplish this? Am I over-complicating it? My gut > > feeling is there is a better way than the following: > > > import itertools > x = [1, 2, 3] > y = list(itertoo

Re: Creating a dictionary

2012-10-09 Thread Roy Smith
In article <50741ffe$0$6574$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: > > > below is the text file i have How to create Facility as a key and then > > assign multiple values to it > > To use Facility as a key in a dict: > >

Re: Private methods

2012-10-10 Thread Roy Smith
In article <1krpdak.u0qy9e1a4knspn%real-not-anti-spam-addr...@apple-juice.co.uk>, real-not-anti-spam-addr...@apple-juice.co.uk (D.M. Procida) wrote: > Mark Lawrence wrote: > > > On 09/10/2012 14:24, D.M. Procida wrote: > > > What exactly is the point of a private method? Why or when would I wa

Re: Basic JSON question: Do I really need the quotes

2012-10-12 Thread Roy Smith
In article , moo...@yahoo.co.uk wrote: > I need to define some configuration in a file that will be manually created. > [...] > json seemed a quick an easy way of achieving this JSON would not be my first choice for a file which needs to be maintained by hand. I've only recently started using

Re: Feedback on my python framework I'm building.

2012-10-14 Thread Roy Smith
In article <507a3365$0$6574$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Remember using PEEK and POKE commands with BASIC back in > 1978? Pretty much impossible in Python. But, trivial to implement as an extension :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: pyw program not displaying unicode characters properly

2012-10-14 Thread Roy Smith
In article , MRAB wrote: > Which codepoint is it? What is the codepoint's name? > > Here's how to find out: > > >>> hex(ord("?")) > '0x190' > >>> import unicodedata > >>> unicodedata.name("?") > 'LATIN CAPITAL LETTER OPEN E' Wow, I never knew you could do that. I usually just google for

Re: pyw program not displaying unicode characters properly

2012-10-15 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > Classically, NNTP did not have "attachments" as seen in MIME email. NNTP (Network News Transport Protocol) and SMTP (Simple Mail Transfer Protocol) are both just ways of shipping around messages. Neither one really knows about attachments. In bo

Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Roy Smith
In article <1b8tk9-un9@chris.zbmc.eu>, tinn...@isbd.co.uk wrote: > The function producing the error is:- > > def get_text(self, idx): # override ! > node = self.items[idx] > > a= [ > ", ".join(node.tags), > node.comment, >

Re: MySQL with Python

2012-10-15 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > For routine database /access/ (that is, someone has created the > database user account that will be used), MySQLdb is the Python adapter > to connect to the server. For using THAT, you basically need to know SQL > (MySQL's flavor in particular), along wit

Re: how to insert random error in a programming

2012-10-15 Thread Roy Smith
In article , rusi wrote: > On Oct 15, 9:00 pm, John Gordon wrote: > > In Debashish Saha > > writes: > > > > > how to insert random error in a programming? > > > > Open the program source file and replace the Nth character with a random > > character. > > I'm reminded of a description of vi

Re: bad httplib latency due to IPv6 use

2012-10-17 Thread Roy Smith
In article <1s42l9-9al@satorlaser.homedns.org>, 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.

Re: bad httplib latency due to IPv6 use

2012-10-17 Thread Roy Smith
In article , Ulrich Eckhardt wrote: > Some updates on the issue: > > The etc/hosts file contains the following lines: > > # localhost name resolution is handled within DNS itself. > # 127.0.0.1 localhost > # ::1 localhost > > As I understand it, those effectively

Re: A desperate lunge for on-topic-ness

2012-10-20 Thread Roy Smith
In article <5081d0c3$0$30003$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Some code might be more conveniently written as a single long line. But I > would argue that nearly never is code more easily *read* as a single long > line, and since code is read much more than it is w

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread Roy Smith
In article , Grant Edwards wrote: > On 2012-10-21, Steven D'Aprano wrote: > > On Sun, 21 Oct 2012 22:43:07 +1100, Chris Angelico wrote: > > > >> On Sun, Oct 21, 2012 at 9:00 PM, Steven D'Aprano > >> wrote: > >>> Er, no. Note spelling of "source code" vs "souce code". Hence the grin. > >> > >>

Re: A desperate lunge for on-topic-ness

2012-10-22 Thread Roy Smith
In article <5084e819$0$29897$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Mon, 22 Oct 2012 07:22:18 +1100, Chris Angelico wrote: > > > On Mon, Oct 22, 2012 at 6:11 AM, Steven D'Aprano > > wrote: > > >>> Ahh. I totally didn't see that, I'm way too used to reading past > >>>

PIL and requests don't get along

2012-10-23 Thread Roy Smith
I have a url from which I can get an image. I want to use PIL to manipulate that image. Getting the image is easy: >>> import requests >>> r = requests.get(url) There's a bunch of factory functions for Image, but none of them seem to take anything that requests is willing to give you. Image.ne

Re: PIL and requests don't get along

2012-10-24 Thread Roy Smith
In article , Kushal Kumaran wrote: > On 23 Oct 2012 14:06:59 -0400, r...@panix.com (Roy Smith) wrote: > > I have a url from which I can get an image. I want to use PIL to > > manipulate that image. Getting the image is easy: > > > > >>> import r

Re: SSH Connection with Python

2012-10-25 Thread Roy Smith
In article , Schneider wrote: > Hi Folkz, > how can i create a SSH-Connection with python? I have to send some > commands to the remote host and parse their answers. > greatz Johannes At a low level, you want to look at the paramiko library. Built on top of that, and adding hoards of neat fu

Re: SSH Connection with Python

2012-10-26 Thread Roy Smith
In article , Gelonida N wrote: > Another problem is, that paramiko depends on pycrypto 2.1+ > which doesn't exist as binary release for python 2.7 I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box. I'm reasonably sure all I did was "pip install paramiko". On the other han

Re: SSH Connection with Python

2012-10-29 Thread Roy Smith
In article , Gelonida N wrote: > The sh module looks intersting, but it's not supported for Windows > platforms. "The X module looks interesting but it's not supported for Windows" is true for many values of X. It's all part of the TCO of using a brain-dead operating system. -- http://mail

Re: Negative array indicies and slice()

2012-10-29 Thread Roy Smith
In article , Andrew Robinson wrote: > Show me an example where someone would write a slice with a negative and > a positive index (both in the same slice); > and have that slice grab a contiguous slice in the *middle* of the list > with orientation of lower index to greater index. It's possib

Re: SSH Connection with Python

2012-10-29 Thread Roy Smith
In article , Gelonida N wrote: > On 10/29/2012 02:10 PM, Roy Smith wrote: > > In article , > > Gelonida N wrote: > > > >> The sh module looks intersting, but it's not supported for Windows > >> platforms. > > > > "The X module look

Re: Negative array indicies and slice()

2012-10-29 Thread Roy Smith
In article , Ian Kelly wrote: > On Mon, Oct 29, 2012 at 9:42 AM, Andrew Robinson > wrote: > > The list was generated in a single pass by many .append() 's, and then > > copied once -- the original was left in place; and then I attempted to slice > > it. > > Note that if the list was generated

Re: Negative array indicies and slice()

2012-10-29 Thread Roy Smith
In article , Ian Kelly wrote: > On Mon, Oct 29, 2012 at 5:24 PM, Roy Smith wrote: > > I think you're missing the point of "amortized constant time". Yes, the > > first item appended to the list will be copied lg(20,000,000) ~= 25 > > times, because the

Re: Obnoxious postings from Google Groups

2012-11-01 Thread Roy Smith
In article <50932111$0$29967$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Huh. If you're messing about with ancient[1] languages like Java, C# and > especially C, you're not a real programmer. Real programmers use modern, > advanced languages like D, Erlang, Go or Haskell. D

Re: How to generate account number?

2012-11-03 Thread Roy Smith
In article , Andriy Kornatskyy wrote: > 'Z05738521581' > 'Z17888279480' > 'Z07395350007' > > Short, human readable and satisfy original requirements. > > Andriy If you really want human readable, it's better to chunk the data up into 3 or 4 digit groups. So, instead of Z05738521581, maybe

Re: is implemented with id ?

2012-11-03 Thread Roy Smith
In article <50959154$0$6880$e4fe5...@news2.news.xs4all.nl>, Hans Mulder wrote: > That's a matter of perspective: in my book, the primary advantage of > working with interned strings is that I can use 'is' rather than '==' > to test for equality if I know my strings are interned. The space > sav

Re: Proper place for everything

2012-11-04 Thread Roy Smith
In article <5096202c$0$29967$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Sat, 03 Nov 2012 22:19:19 -0700, Aahz wrote: > > > In article <509441cb$0$29967$c3e8da3$54964...@news.astraweb.com>, Steven > > D'Aprano wrote: > >>On Fri, 02 Nov 2012 04:20:20 -0700, Jason Benjamin

__unicode__() works, unicode() blows up.

2012-11-04 Thread Roy Smith
Environment: Python-2.7.3 Ubuntu Precise mongoengine 0.6.20 I have a class which includes a __unicode__() method: class User(mongoengine.Document): def __unicode__(self): return self.username If I create an instance of this class by calling the constructor directly, self.usern

Re: __unicode__() works, unicode() blows up. (Never mind!)

2012-11-04 Thread Roy Smith
In article , Roy Smith wrote: > >>> print u.__unicode__() > None > > >>> print unicode(u) > Traceback (most recent call last): > File "", line 1, in > TypeError: coercing to Unicode: need string or buffer, NoneType found > > What&#

Re: Obnoxious postings from Google Groups

2012-11-05 Thread Roy Smith
In article , Chris Angelico wrote: > It's nothing to do with operating system. File names are names, and > spaces in them are seldom worth the hassle unless you manipulate those > files solely using a GUI. That's a very ascii-esqe attitude. In a fully unicode world, I could easily see using U

Re: Obnoxious postings from Google Groups

2012-11-06 Thread Roy Smith
In article <50989a16$0$29980$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Shell do not [quote strings, etc] because they > are designed for lazy users and merely aim to be "good enough". Well, sort of. Or, perhaps more correctly, "Yes, but that's a good thing". Shells are d

Re: Multi-dimensional list initialization

2012-11-06 Thread Roy Smith
In article <5099ec1d$0$21759$c3e8da3$76491...@news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 07 Nov 2012 00:23:44 +, MRAB wrote: > > >> Incorrect. Python uses what is commonly known as call-by-object, not > >> call-by-value or call-by-reference. Passing the list by value would > >>

Re: Obnoxious postings from Google Groups

2012-11-06 Thread Roy Smith
In article , Gregory Ewing wrote: > Steven D'Aprano wrote: > > The downside is that if spaces are not argument separators, then you need > > something else to be an argument separator. Or you need argument > > delimiters. Or strings need to be quoted. Programming languages do these > > things

Re: creating size-limited tar files

2012-11-07 Thread Roy Smith
In article <509ab0fa$0$6636$9b4e6...@newsspool2.arcor-online.net>, Alexander Blinne wrote: > I don't know the best way to find the current size, I only have a > general remark. > This solution is not so good if you have to impose a hard limit on the > resulting file size. You could end up having

Re: Invalid syntax

2012-11-07 Thread Roy Smith
In article , Demian Brecht wrote: > On 2012-11-07, at 3:17 PM, Smaran Harihar wrote: > > Any idea where am I going wrong? > > Looks like you're missing a closing parenthesis: What I find is useful in situations like this is to just let emacs auto-indent the code. When it starts indenting (o

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread Roy Smith
In article <18134e77-9b02-4aec-afb0-794ed900d...@googlegroups.com>, bruceg113...@gmail.com wrote: > Is there a simpler way to modify all arguments in a function before using the > arguments? > > For example, can the below code, in the modify arguments section be made into > a few statements?

A gnarly little python loop

2012-11-10 Thread Roy Smith
I'm trying to pull down tweets with one of the many twitter APIs. The particular one I'm using (python-twitter), has a call: data = api.GetSearch(term="foo", page=page) The way it works, you start with page=1. It returns a list of tweets. If the list is empty, there are no more tweets. If t

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Roy Smith
In article , Ian Kelly wrote: > On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: > > I would not assume that. The origin is a point, just like any other. > > With a Line class, you could deem a zero-length line to be like a > > zero-element list, but Point(0,0) is more like the tuple (0,0

Re: A gnarly little python loop

2012-11-11 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > deque( > imap( > process, > chain.from_iterable( > takewhile(bool, imap(partial(api.GetSearch, term), count(1), > maxlen=0) > > ;) If I wanted STL, I would still be writing C++ :-) -- http://mail.pyth

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Mark Lawrence wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: > > > > Plain wrong. Vectors are not defined *from any origin*. > > > > So when the Captain says "full speed ahead, steer 245 degrees", you > haven't the faintest idea where you're going, because you have no origin?

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Oscar Benjamin wrote: > But then I'm assuming you meant that 245 degrees was a bearing > relative to North. Was it supposed to be relative to my current angle? > Truthfully I wouldn't know what to do without asking the captain a > couple more questions. Granted, this requires some

Re: Strange object identity problem

2012-11-12 Thread duncan smith
On 12/11/12 13:40, F.R. wrote: On 11/12/2012 02:27 PM, Robert Franke wrote: Hi Frederic, [...] bas = {} for year in range (2010, 2013): ba = st.runs ('BA', '%d-01-01' % year, '%d-12-31' % year) ba.run () print year, id (ba) bas [year] = ba 2010 150289932 2011 150835852 2012 1

Re: Generate unique ID for URL

2012-11-13 Thread Roy Smith
In article <0692e6a2-343c-4eb0-be57-fe5c815ef...@googlegroups.com>, Richard wrote: > Hello, > > I want to create a URL-safe unique ID for URL's. > Currently I use: > url_id = base64.urlsafe_b64encode(url) > > >>> base64.urlsafe_b64encode('docs.python.org/library/uuid.html') > 'ZG9jcy5weXRob24u

Re: Generate unique ID for URL

2012-11-13 Thread Roy Smith
In article <1ce88f36-bfc7-4a55-89f8-70d1645d2...@googlegroups.com>, Richard wrote: > So the use case - I'm storing webpages on disk and want a quick retrieval > system based on URL. > I can't store the files in a single directory because of OS limitations so > have been using a sub folder str

Re: Subprocess puzzle and two questions

2012-11-13 Thread Roy Smith
In article , w...@mac.com wrote: > I need to time the operation of a command-line utility (specifically > nslookup) from within a python program I'm writing. Ugh. Why are you doing this? Shelling out to nslookup is an incredibly slow and clumsy way of doing name translation. What you really

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , William Ray Wing wrote: > On Nov 13, 2012, at 11:41 PM, Roy Smith wrote: > > > In article , > > w...@mac.com wrote: > > > >> I need to time the operation of a command-line utility (specifically > >> nslookup) from within a python progr

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
I wrote: >> Oh, my. You're using DNS as a replacement for ping? Fair enough. In >> that case, all you really care about is that you can connect to port 53 >> on the server... >> >> s = socket.socket() >> s.connect(('8.8.8.8', 53)) In article , Chris Angelico wrote: >That assumes that (a) the

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , Chris Angelico wrote: > I'm slightly surprised that there's no way with the Python stdlib to > point a DNS query at a specific server Me too, including the "only slightly" part. The normal high-level C resolver routines (getaddrinfo/getnameinfo, or even the old gethostbyname se

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , Chris Angelico wrote: > Indeed. But Python boasts that the batteries are included, and given > the wealth of other networking facilities that are available, it is a > bit of a hole that you can't run DNS queries in this way. Think of the socket and struct modules as a pile of carbo

Re: debugging in eclipse

2012-11-15 Thread Roy Smith
In article , chip9m...@gmail.com wrote: > Now I would like to debug it in eclipse.. Heh. It took me a while to realize that the subject line was not referring to http://en.wikipedia.org/wiki/Solar_eclipse_of_November_13,_2012 -- http://mail.python.org/mailman/listinfo/python-list

Re: debugging in eclipse

2012-11-15 Thread Roy Smith
In article , Dave Angel wrote: > I'd also add a print statement, just to assure yourself that it's running. My trick to make sure something is running is to add "assert 0". To be fair, I usually start by adding a print statement, as Dave suggests. If I see the output, I know it ran. But if

Re: Subprocess puzzle and two questions

2012-11-15 Thread Roy Smith
In article , Nobody wrote: > That's because the high-level routines aren't tied to DNS. This is true. >> gethostbyname() and getaddrinfo() use the NSS (name-service switch) > mechanism, which is configured via /etc/nsswitch.conf. Depending upon > configuration, hostnames can be looked up via a

Re: editing conf file

2012-11-16 Thread Roy Smith
Ulrich Eckhardt wrote: > in general importing configuration data by loading and > executing code is a questionable approach. The problem is in particular > that the code parser is always more strict with the syntax than a > configuration file should be. Also, it presents the danger of code >

Re: Python Script for Colorizing Traceroute Output (apologies for top-post)

2012-11-17 Thread Roy Smith
In article , w...@mac.com wrote: > On Nov 17, 2012, at 10:04 AM, Jordan Bylsma wrote: > > > I'm looking into writing a python script that colorizes particular hops > > when using traceroute. Anyone run across something like this? I don't think > > it would be extremely difficult to write but

Re: Python Interview Questions

2012-11-18 Thread Roy Smith
In article <50a8acdc$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Use a list when you want a list of items that should all be treated the > same way [...] or when you need a collection of items where the order they > are in is > important: > > Use a tuple when you wan

Re: Python Interview Questions

2012-11-18 Thread Roy Smith
In article <50a911ec$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Oh I'm sorry, did something I say suggest that the couple of examples I > gave are the *only* acceptable uses? My apologies for not giving an > exhaustive list of every possible use of lists and tuples,

Re: Python Interview Questions

2012-11-18 Thread Roy Smith
In article <50a97de0$0$29983$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > > The stack that's returned is a list. It's inherently a list, per the > > classic definition: > > Er, no, it's inherently a blob of multiple text lines. No, it's a list that looks like (taken from the

Re: Python Interview Questions

2012-11-19 Thread Roy Smith
In article <50a9e5cf$0$21863$c3e8da3$76491...@news.astraweb.com>, Steven D'Aprano wrote: > I see. It wasn't clear from your earlier description that the items had > been post-processed from collections of raw log lines to fixed records. Well, I did provide the code that does this. > But it d

Re: Python Interview Questions

2012-11-19 Thread Roy Smith
OK, I've just read back over the whole thread. I'm really struggling to understand what point you're trying to make. I started out by saying: > Use a list when you need an ordered collection which is mutable (i.e. > can be altered after being created). Use a tuple when you need an > immutabl

Re: Python Interview Questions

2012-11-19 Thread Roy Smith
In article <50aac3d8$0$29983$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > By the way, your news client seems to be mangling long URLs, by splitting > them when they exceed the maximum line length. Hmmm. So it did. My bad. -- http://mail.python.org/mailman/listinfo/python-li

Re: Python Interview Questions

2012-11-19 Thread Roy Smith
In article <50aac66c$0$29983$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > I'm asking about the case where one might want the key to remain mutable > even after it is used as a key, but can't because Python won't let you. Ah. Now I see what you're getting at. Thank you. Well

Re: Printing time in "at" format?

2012-11-20 Thread Roy Smith
as 'at' does" > > If it's the former, it's pretty easy--'at' accepts a wide variety of > formats. Fortunately, it's the former. Since posting my original query, I have discovered by experimentation that the API also accepts a string of digit

Re: Is it bad style to override the built-in function `type`?

2012-11-23 Thread Roy Smith
In article , Michael Herrmann wrote: > do you think it's bad style to override the built-in function `type`? I'm > co-developing a GUI automation library called Automa > (http://www.getautoma.com) and 'type' would be a very fitting name for a > function that generates artificial key strokes.

argparse -- mutually exclusive sets of arguments?

2012-11-23 Thread Roy Smith
My command either takes two positional arguments (in which case, both are required): $ command foo bar or the name of a config file (in which case, the positional arguments are forbidden): $ command --config file How can I represent this with argparse; add_mutually_exclusive_group() isn't qu

Re: How to pass class instance to a method?

2012-11-26 Thread Roy Smith
Steven D'Aprano wrote: > Given the practical reality that documentation is often neglected, there > is a school of thought that says that *code* is the One True source of > information about what the code does, that documentation is at best a > hint or at worst completely redundant. Yes, there

Re: "non central" package management

2012-11-27 Thread Roy Smith
In article <8ea52e1b-2e02-40b2-8ce0-fcce7fc2e...@googlegroups.com>, Miki Tebeka wrote: > Greetings, > > The usual package mangers (easy_install, pip ...) install packages in one > central location. > > I'm looking for a solution that will allow every project (which run on the > same machine)

Re: "non central" package management

2012-11-27 Thread Roy Smith
In article , Miki Tebeka wrote: > > When we deploy, we create a new virtualenv, then do > > "pip install -r requirements.txt". > 1. Do you do that for every run? Well, sort of. We are currently using a single virtualenv per deployment host. Each time we deploy new code, we checkout all th

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

2012-11-28 Thread Roy Smith
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 import it fine: $ python Python 2.7.3 (default, Aug 1 2012, 05:1

Re: Exponential arrival distribution in Python

2012-11-29 Thread duncan smith
On 28/11/12 21:34, Ricky wrote: Hi all, I am doing a project on traffic simulation. I want to introduce exponential arrival distribution to precede this task. Therefore I want write a code in python for exponential arrival distribution. I am very new for programming and if anybody can help m

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

2012-11-29 Thread Roy Smith
In article <50b78e26$0$6945$e4fe5...@news2.news.xs4all.nl>, Hans Mulder wrote: > That is baffling indeed. It looks like nose is adding some > directory to sys.path, which contains a module pyza.py instead > of a package. We finally figured it out. As it turns out, that's pretty close. > Anot

Weird exception handling behavior -- late evaluation in except clause

2012-12-02 Thread Roy Smith
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 never notices that foo is not defined until it's too late

Re: How to determine if printing is being a bottleneck in my code?

2012-12-04 Thread Roy Smith
In article <29c74a30-f017-44b5-8a3d-a3c0d6592...@googlegroups.com>, SherjilOzair wrote: > Hello list, > > When it comes to printing things while some computation is being done, there > are 2 extremes. > > 1. printing speed is slower than data-to-print generation speed. In this > case, printi

Re: A question about readability

2012-12-07 Thread Roy Smith
In article , Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): > result = sum(int(data) for data in line.split(';')) > print(result) That sum() line is a bit of a mouthful. I would refactor it into something like this: > for line

Re: TypeError: 'in ' requires string as left operand, not Element

2012-12-09 Thread Roy Smith
In article <8c78344a-8019-450a-bfdf-13508bf75...@googlegroups.com>, Victor Hooi wrote: > Hi, > > I'm getting a strange error when I try to run the following: > > for root, dirs, files in os.walk('./'): > for file in files: > if file.startswith('ml') and file.endswith('.

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread duncan smith
On 10/12/12 22:38, qbai...@ihets.org wrote: I need help with a program i am doing. it is a cryptography program. i am given a regular alphabet and a key. i need to use the user input and use the regular alphabet and use the corresponding letter in the key and that becomes the new letter. i hav

Re: What are the minimum requirements to get a job in?

2012-12-14 Thread Roy Smith
In article , Stefan Behnel wrote: > suresh.pinn...@gmail.com, 14.12.2012 03:49: > > My aim is to get a job into google or cisco or facebok. > > Why? > > There are lots of attractive places to work at. Choosing a less visible one > means that you have a higher chance of getting hired in the fir

Re: What are the minimum requirements to get a job in?

2012-12-14 Thread Roy Smith
In article <50cbaf19$0$29991$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Fri, 14 Dec 2012 09:48:54 -0500, Roy Smith wrote: > > > On the other hand, as somebody who's looking to hire software engineers, > > I can tell you that we loo

Re: What are the minimum requirements to get a job in?

2012-12-14 Thread Roy Smith
In article , Chris Angelico wrote: > If the boss's vision is anything to go by, we're going to be bigger > than Microsoft, eBay, Facebook, and Google combined, and all by early > 2013. That's the kind of attitude you need to be at a startup. -- http://mail.python.org/mailman/listinfo/python-l

Re: where to view open() function's C implementation source code ��

2012-12-17 Thread Roy Smith
In article , iMath wrote: > where to view open() function's C implementation source code ? http://www.python.org/download/releases/ Download the source for the version you're interested in. -- http://mail.python.org/mailman/listinfo/python-list

Re: where to view open() function's C implementation source code ?

2012-12-18 Thread Roy Smith
In article , iMath wrote: > � 2012”N12ŒŽ18“��Š�“�UTC+8‰�Œ�1时35分58秒,Roy > Smith写道: > > In article , > > > > iMath wrote: > > > > > > > > > where to view open() function's C implementation

Re: help with making my code more efficient

2012-12-20 Thread Roy Smith
In article , "larry.mart...@gmail.com" wrote: > On Thursday, December 20, 2012 5:38:03 PM UTC-7, Chris Angelico wrote: > > On Fri, Dec 21, 2012 at 11:19 AM, larry.mart...@gmail.com > > > > wrote: > > > > > This code works, but it takes way too long to run - e.g. when cdata has > > > 600,000

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-23 Thread Roy Smith
In article , prilisa...@googlemail.com wrote: > Thanks to all your answers, I have read a lot about namespaces, but still > there's something I do not understood. I have tried your example but as I > expected: > > line 13, in HandoverSQLCursor > curs.execute("SELECT * FROM lager") > Attrib

Integer as raw hex string?

2012-12-24 Thread Roy Smith
I have an integer that I want to encode as a hex string, but I don't want "0x" at the beginning, nor do I want "L" at the end if it happened to be a long. The result needs to be something I can pass to int(h, 16) to get back my original integer. The brute force way works: h = hex(i) ass

Re: Custom alphabetical sort

2012-12-24 Thread Roy Smith
In article <40d108ec-b019-4829-a969-c8ef51386...@googlegroups.com>, Pander Musubi wrote: > Hi all, > > I would like to sort according to this order: > > (' ', '.', '\'', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', > 'A', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 'b', 'B',

Re: Integer as raw hex string?

2012-12-24 Thread Roy Smith
In article , Tim Chase wrote: > On 12/24/12 09:36, Roy Smith wrote: > > I have an integer that I want to encode as a hex string, but I don't > > want "0x" at the beginning, nor do I want "L" at the end if it happened > > to be a long. The result

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

2012-12-24 Thread Roy Smith
In article , Alister wrote: > Indeed due to the poor quality of most websites it is not possible to be > 100% accurate for all sites. > > personally I would start by checking the doc type & then the meta data as > these should be quick & correct, I then use chardectect only if these > fail t

Re: Custom alphabetical sort

2012-12-24 Thread Roy Smith
In article <46db479a-d16f-4f64-aaf2-76de65418...@googlegroups.com>, Pander Musubi wrote: > > I'm assuming that doesn't correspond to some standard locale's collating > > order, so we really do need to roll our own encoding (and that you have > > a good reason for wanting to do this). > > It i

Re: Finding the name of a function while defining it

2012-12-25 Thread Roy Smith
In article , Abhas Bhattacharya wrote: > While I am defining a function, how can I access the name (separately as > string as well as object) of the function without explicitly naming > it(hard-coding the name)? > For eg. I am writing like: > def abc(): > #how do i access the function abc

Re: How to get time.strptime()?

2012-12-26 Thread Roy Smith
In article <0e36e143-5103-4b4b-aaa9-b7b1b7686...@googlegroups.com>, Gnarlodious wrote: > This is problem that has unduly vexed me. When you start learning Python they > don't tell you about these sharp edges. Someone needs to explain. The same thing happens when you're born. You spend your en

Re: Finding the name of a function while defining it

2012-12-27 Thread Roy Smith
In article <50dc29e9$0$29967$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 26 Dec 2012 23:46:31 -0800, Abhas Bhattacharya wrote: > > >> > two = lamba : "one" > >> > one = two > >> > >> > Which one of these is the "name" of the function? > [...] > > If i call one() and t

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