Re: Grouping code by indentation - feature or ******?

2005-03-25 Thread Skip Montanaro
>> What do you guys think about Python's grouping of code via >> indentation? Peter> This is a Python newsgroup. Assume that we all have been Peter> brainwashed. +1 QOTW. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: SimpleRPCServer

2005-03-25 Thread Skip Montanaro
Esben> What i don't know is how to the client ip. I would think I should Esben> override the _marshalled_dispatch method but I can't quite grasp Esben> it all. First, from my reading of SimpleXMLRPCServer, I don't think _dispatch() belongs at that level. It belongs in the request han

Re: Python slogan, was Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Skip Montanaro
>> Or, paraphrasing Mark Twain, "Python is the worst possible >> programming language, except for all the others." Peter> I've been trying to establish that a while ago, but would Peter> attribute it to Winston Churchill -- so I'm a little confused Peter> now. Google thinks i

Re: Python Cookbook 2nd Ed

2005-03-28 Thread Skip Montanaro
Will> Is the second edition of the Python Cookbook worth getting if you Will> have the first edition? How much new material is there in the 2nd Will> edition? While I have dived into it yet, I received a copy from O'Reilly last week. It's about twice the size of the first edition, and

Re: Table of Python Packages, updated

2005-03-29 Thread Skip Montanaro
Seo> Hello, comp.lang.python, and catalog-sig, Some of you may remember Seo> my mail with the very same subject last year. :-) I have continued Seo> to maintain the table, and here's the updated result: Seo> http://sparcs.kaist.ac.kr/~tinuviel/pypackage/list.cgi Very nice. I hav

Re: Table of Python Packages, updated

2005-03-29 Thread Skip Montanaro
>> Would it make sense to add a "distutils" column for those packages >> that can be installed from source using "python setup.py install" or >> do you assume that all the listed packages have that capability? Seo> Are you suggesting linking to the project's homepage, or upstream

Python performance tips page moved to wiki

2005-03-29 Thread Skip Montanaro
I dumped my old fastpython.html web page: http://manatee.mojam.com/~skip/python/fastpython.html in favor of a page on the Python wiki: http://www.python.org/moin/PythonSpeed/PerformanceTips Now everybody can help fix warts, add content, etc, etc, etc. References to the old page are red

Re: urllib.urlretireve problem

2005-03-30 Thread Skip Montanaro
>> For example, for Temporary Name Resolution Failure, python raises an >> exception which I've handled well. The problem lies with obsolete >> urls where no exception is raised and I end up having a 404 error >> page as my data. Diez> It makes no sense having urllib generatin

Re: Python 2.4.1 build (configure) ?

2005-03-30 Thread Skip Montanaro
Venkat> When I checked the .py sources (in Lib folder) thru grep for Venkat> 'ipv6', I see the same references I'd see, if I ran the Venkat> configure command without the --enable-ipv6 option. Is that Venkat> normal or is there an issue I need to address here. Yes, it's normal.

Re: string goes away

2005-03-31 Thread Skip Montanaro
>>> upper_list = map(string.upper, list_of_str) Andreas> What am I supposed to do instead? Try [s.upper() for s in list_of_str] Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: string goes away

2005-03-31 Thread Skip Montanaro
Andreas> Yeeh, I was expecting something like that. The only reason to Andreas> use map() at all is for improving the performance. That is Andreas> lost when using list comprehensions (as far as I know). So, Andreas> this is *no* option for larger jobs. Did you test your hypothes

Re: Spider - path conflict [../test.htm,www.nic.nl/index.html]

2005-04-01 Thread Skip Montanaro
martijn> I thought I was ready with my own spider... But then there was martijn> a bug, or in other words a missing part in my code. martijn> I forget that people do this in website html: martijn> http://www.nic.nl/monkey.html";>is oke martijn> error martijn> error pydoc

Re: Looking for Benchmarklets to improve pyvm

2005-04-01 Thread Skip Montanaro
Stelios> I'm collecting small testlets to benchmark it, discover Stelios> bottlenecks and improve it. They should be small and not use Stelios> any crazy modules. Only [sys, os, itertools, thread, Stelios> threading, math, random] for now. Take a look around for Marc Andre Lembu

Re: Simple thread-safe counter?

2005-04-01 Thread Skip Montanaro
Paul> I'd like to have a function (or other callable object) that Paul> returns 0, 1, 2, etc. on repeated calls. ... Paul> There should never be any possibility of any number getting Paul> returned twice, or getting skipped over, even if f is being called Paul> from multipl

Propagating poorly chosen idioms

2005-04-05 Thread Skip Montanaro
Peter> unitttest is surely not the be all and end all of Python unit Peter> testing frameworks... but it's one of the batteries included in Peter> the standard distribution, and it's pretty trivial to get started Peter> using it, unless maybe you try to go by the documentation ins

Re: Thoughts on some stdlib modules

2005-04-11 Thread Skip Montanaro
>> I guess the other thing to compare to is something like SciPy, which >> is a kind of specialized distribution of Python for scientific >> applications. Robert> No, Scipy is just a (large) package. Enthon, on the other hand, Robert> is just such a distribution. I'm sorry, y

Re: Weird...

2005-04-11 Thread Skip Montanaro
>>> {'a':1,'b':'2','c':[3,4]}.keys() ['a', 'c', 'b'] Joshua> How come? :-) Because: >>> {'A':1,'b':'2','Cat':[3,4]}.keys() ['A', 'b', 'Cat'] :-) For more detail: http://www.python.org/doc/faq/general.html#id48 Skip -- http://mail.python.org/mailman/listinfo/python-l

Re: smtplib does not send to all recipients

2005-04-11 Thread Skip Montanaro
dccarson> I changed debuglevel to 1 and looked at the response on the dccarson> recipient names. They are BOTH accepted, but still only my id dccarson> (d123456) receives the e-mail. The long id (d1234567890) dccarson> never gets the e-mail. Here is the excerpt of the exchange.

Re: permission

2005-04-12 Thread Skip Montanaro
James> Is it possible to check if you have permission to access and or James> change a directory or file? Yes, but it's generally much easier to try, then recover from any errors: try: f = open(somefile, "a") except IOError, msg: print "can't open", somefile, "for

Re: SimpleXMLRPCServer - disable output

2005-04-14 Thread Skip Montanaro
codecraig> I thought I posted this, but its been about 10min and hasnt codecraig> shown up on the group. Patience... codecraig> localhost - - [14/Apr/2005 16:06:28] "POST /RPC2 HTTP/1.0" 200 - codecraig> Anyhow, is there a way I can surpress that so its not printed codecraig

Re: python.exe on Mac OS X!?

2005-04-17 Thread Skip Montanaro
Rodney> I did a source code build of Python 2.4.1 on OS X (10.3.8) and Rodney> the executable produced was 'python.exe'. Can someone tell me Rodney> whether this is a bug, feature, or UserError? The default file system on MacOSX is case insensitive. As a result the .exe extension is

Re: Wrapping C++ Class Heirachy in Python

2005-04-18 Thread Skip Montanaro
Roy> I've been playing around with ctypes Roy> (http://starship.python.net/crew/theller/ctypes/) recently. So Roy> far, it looks pretty cool. Wrapping C++ libraries? Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: an unchanging URL for Python documentation

2005-04-18 Thread Skip Montanaro
steve> I propose that an additional a URL be set up for the Python HTML steve> documentation. This URL will always contain the current version steve> of the documentation. Suppose we call it "current". Then (while steve> 2.4 is still the current version) the documentation for th

Re: Proposal: an unchanging URL for Python documentation

2005-04-18 Thread Skip Montanaro
Skip> But appears to be firefox-specific. Michael> Works for me with both Firefox and IE6 under WinXP The wikalong.org thing is firefox-specific. You trimmed too much from my reply. Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: XML-RPC -- send file

2005-04-19 Thread Skip Montanaro
codecraig> I thought i read somewhere that by using pickle or something, codecraig> that u could get a string representation of your object (or a codecraig> file in my case) and send that. Any ideas? Sure: stuff = xmlrpclib.Binary(open(somefile).read()) server.call_some_remo

Re: Refactoring in Python.

2005-04-19 Thread Skip Montanaro
Peter> I am trying to write Master Thesis on refactoring Python code. Peter> Where should I look for information? I'm not sure, but one piece of code to check out would probably be Bicycle Repair Man, a early-stage prototype refactoring tool for Python. I don't recall where it's hosted.

Re: XML-RPC -- send file

2005-04-19 Thread Skip Montanaro
codecraig> how would I decode it? Assuming you have Python at the other end and you get a Binary object instead of a string, access its data attribute. OTOH, xmlrpclib may automatically decode the wrapper object for you. In any case, I have two further recommendations: * Check the xmlr

Re: gc.DEBUG_LEAK and gc.garbage

2005-04-19 Thread Skip Montanaro
Cesar> I have set the DEBUG_LEAK flag with the GC and in the program Cesar> cycle printed the length of the garbage list. Is this enough to Cesar> determine if there is a leak in the python code? (the value Cesar> rises). That suggests to me that you have objects with __del__ meth

Re: XML-RPC -- send file

2005-04-20 Thread Skip Montanaro
codecraig> stefan: i added, "return 1" to my sendFile method on the server...took codecraig> care of the error, thanks. Yes, by default XML-RPC doesn't support objects like Python's None. As the error message indicated you have to enable allow_none to permit transmission of None. Skip

Re: Python Debugger with source code tracking ability

2005-04-20 Thread Skip Montanaro
Tran> I am new to Python and desperated to look for a good Python Tran> debugger. I mean a debugger with source coding tracking. For Tran> C/C++, emacs and gud offers execellent development env. The source Tran> code tracking is extremely useful for recursive functions. There is

Re: regex over files

2005-04-26 Thread Skip Montanaro
Robin> So we avoid dirty page writes etc etc. However, I still think I Robin> could get away with a small window into the file which would be Robin> more efficient. It's hard to imagine how sliding a small window onto a file within Python would be more efficient than the operating sys

Re: regex over files

2005-04-26 Thread Skip Montanaro
>> It's hard to imagine how sliding a small window onto a file within Python >> would be more efficient than the operating system's paging system. ;-) Robin> well it might be if I only want to scan forward through the file Robin> (think lexical analysis). Most lexical analyzers use

Re: regex over files

2005-04-27 Thread Skip Montanaro
Robin> I implemented a simple scanning algorithm in two ways. First buffered scan Robin> tscan0.py; second mmapped scan tscan1.py. ... Robin> C:\code\reportlab\demos\gadflypaper>\tmp\tscan0.py dingo.dat Robin> len=139583265 w=103 time=110.91 Robin> C:\code\reportlab\de

Re: regex over files

2005-04-28 Thread Skip Montanaro
Bengt> To be fairer, I think you'd want to hoist the re compilation out Bengt> of the loop. The re module compiles and caches regular expressions, so I doubt it would affect the runtime of either version. Bengt> But also to be fairer, maybe include the overhead of splitting Bengt

Trying to wrap my head around futures and coroutines

2014-01-06 Thread Skip Montanaro
I've been programming for a long while in an event&callback-driven world. While I am comfortable enough with the mechanisms available (almost 100% of what I do is in a PyGTK world with its signal mechanism), it's never been all that satisfying, breaking up my calculations into various pieces, and t

Re: Trying to wrap my head around futures and coroutines

2014-01-06 Thread Skip Montanaro
>From the couple responses I've seen, I must have not made myself clear. Let's skip specific hypothetical tasks. Using coroutines, futures, or other programming paradigms that have been introduced in recent versions of Python 3.x, can traditionally event-driven code be written in a more linear mann

Re: Porting mailing list underused?

2014-01-10 Thread Skip Montanaro
> Anyone in the > know who can explain this phenomenon? I don't think I can explain it authoritatively, but I can hazard a guess. Skimming the archives sorted by author, it looks like most/all the correspondents are Python core developers. That leads me to believe this was a list created for the c

Re: How to get Mac address of ethernet port?

2014-01-11 Thread Skip Montanaro
This is slightly longer than ChrisA's second solution: >>> import uuid >>> s = "%12x" % uuid.getnode() >>> ":".join(x+y for x, y in zip(s[::2], s[1::2])) '18:03:73:cb:2a:ee' Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3.x adoption

2014-01-14 Thread Skip Montanaro
> What's the problem with Python 3.x? It was first released in 2008, but > web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... What makes you think anything's wrong? Major changes to any established piece of s

Re: data validation when creating an object

2014-01-16 Thread Skip Montanaro
I suspect when best to validate inputs depends on when they come in, and what the cost is of having objects with invalid state. If the input is something that is passed along when the object is instantiated, you kind of have to validate in __init__ or __new__, right? Let's create a stupid example:

Re: Python 1.0 - release date?

2014-01-21 Thread Skip Montanaro
> I want to say August of 1993, but there are apparently those who disagree. Misc/HISTORY says 26 January 1994: === ==> Release 1.0.0 (26 January 1994) <== === Actually, Misc/HISTORY has release headings going back as far as

datetime as subclass of date

2014-01-23 Thread Skip Montanaro
This took my by surprise just now: >>> import datetime >>> now = datetime.datetime.now() >>> isinstance(now, datetime.datetime) True >>> isinstance(now, datetime.time) False >>> isinstance(now, datetime.date) True >>> issubclass(datetime.datetime, datetime.date) True I'd never paid any attention

Re: datetime as subclass of date

2014-01-24 Thread Skip Montanaro
One thing that always reinforced my notion that issubclass(datetime.datetime, datetime.date) should be False is that the presence of of date and time methods gives me a mental image of delegation, not inheritance. That is, it "feels" like a datetime object is the aggregation of a date object and a

Highlighting program variables instead of keywords?

2014-01-26 Thread Skip Montanaro
My son sent me a link to an essay about highlighting program data instead of keywords: https://medium.com/p/3a6db2743a1e/ I think this might have value, especially if to could bounce back and forth between both schemes. Is anyone aware of tools like this for Python? Bonus points for pointers to a

Re: Highlighting program variables instead of keywords?

2014-01-26 Thread Skip Montanaro
> What it is doing is color coding user-supplied identifiers, with different > color for each one. I found that confusing to read. I think it would take some time to get used to, and I don't think it would be the only way I'd like to view my program. I think an interactive pylint (or pyflakes or

Re: Wikipedia XML Dump

2014-01-28 Thread Skip Montanaro
> Another point: > sax is painful to use compared to full lxml (dom) > But then sax is the only choice when files cross a certain size > Thats why the above question No matter what the choice of XML parser, I suspect you'll want to convert it to some other form for processing. Skip -- https://ma

pytz question: GMT vs. UTC

2014-01-29 Thread Skip Montanaro
According ato the pytz doc (http://pytz.sourceforge.net/): "‘UTC’ is Universal Time, also known as Greenwich Mean Time or GMT in the United Kingdom." If they are equal, why don't timezone objects created from those two strings compare equal? >>> pytz.timezone("UTC") == pytz.timezone("GMT") False

UTC "timezone" causing brain explosions

2014-01-29 Thread Skip Montanaro
Following up on my earlier note about UTC v. GMT, I am having some trouble grokking attempts to convert a datetime into UTC. Consider these three values: >>> import pytz >>> UTC = pytz.timezone("UTC") >>> UTC >>> LOCAL_TZ = pytz.timezone("America/Chicago") >>> LOCAL_TZ >>> now = datetime.datetim

Re: end quote help for a newbie

2014-01-30 Thread Skip Montanaro
Not sure if this is exactly what you're asking, but perhaps you want triple quotes? >>> print "now is the time for all good men ..." now is the time for all good men ... >>> print '''now is the time for "all good men" ...''' now is the time for "all good men" ... It's not easy to visually disting

Re: how to iterate all sub-element in a list

2014-01-31 Thread Skip Montanaro
Google for "python flatten list." This question comes up frequently, though I'm not sure if that's because it's a common homework problem or because people are unaware of the += operator (or extend method) for lists, and so build lists-of-lists when they could just build them flat in the first pla

Re: Why this throws an UnboundLocalError ?

2014-01-31 Thread Skip Montanaro
> That might be an indication of good code design :) Or he got lucky and all his previous globals were mutable. :) Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: __init__ is the initialiser

2014-02-02 Thread Skip Montanaro
On Sun, Feb 2, 2014 at 9:14 PM, Dave Angel wrote: > And when the q-bits get entangled up, we won't know the question > till after the answer has collapsed. Won't looking at the answer change it? Skip -- https://mail.python.org/mailman/listinfo/python-list

undefined symbol: _PyUnicodeUCS4_AsDefaultEncodedString

2014-02-03 Thread Skip Montanaro
For various reasons at work, we get Python from a third party. I just installed VTK for OpenSuSE on one of my desktop machines using zypper. When I import it from /usr/bin/python (2.7.3), the import works just fine. When I try to import it from our vendor-provided Python (2.7.2), I get this traceba

Re: undefined symbol: _PyUnicodeUCS4_AsDefaultEncodedString

2014-02-03 Thread Skip Montanaro
On Mon, Feb 3, 2014 at 12:27 PM, Chris Angelico wrote: > On Tue, Feb 4, 2014 at 4:41 AM, Skip Montanaro wrote: >> I think this means that at configure time, OpenSuSE and our vendor >> chose different values for the --enable-unicode option. Is that >> correct? > > Ea

Re: undefined symbol: _PyUnicodeUCS4_AsDefaultEncodedString

2014-02-03 Thread Skip Montanaro
> Good luck getting this fixed. Even if you do manage to get your vendor > to start shipping wide builds, you're going to have people screaming > about how much more RAM their processes use now :( Never mind that > other Linux builds of Python have done the same thing for years. Our vendor hasn't

Re: system wide mutex

2014-02-09 Thread Skip Montanaro
> Which one is most recommended to use for mutex alike locking to > achieve atomic access to single resource: > > - fcntl.lockf > - os.open() with O_SHLOCK and O_EXLOCK > - https://pypi.python.org/pypi/lockfile/0.9.1 > - https://pypi.python.org/pypi/zc.lockfile/1.1.0 > - any other ? As the author

Re: system wide mutex

2014-02-09 Thread Skip Montanaro
On Sun, Feb 9, 2014 at 8:45 AM, Roy Smith wrote: > This is true of all mutexes, no? Hmmm... You might well be right. I thought that use of the O_EXLOCK flag in the open(2) system call would prevent other processes from opening the file, but (at least on my Mac) it just blocks until the first proc

I'm missing something here...

2016-01-11 Thread Skip Montanaro
Here's a dumb little bit of code, adapted from a slightly larger script: #!/usr/bin/env python "dummy" import glob import os def compare_prices(*_args): "dummy" return set() def find_problems(cx1, cx2, cx3, prob_dates): "dummy" for fff in sorted(glob.glob("/path/to/*.nrm")):

Re: I'm missing something here...

2016-01-11 Thread Skip Montanaro
Sorry, I should have been explicit. prob_dates (the actual argument of the call) is a set. As far as I know pylint does no type inference, so pylint can't tell if the LHS and RHS of the |= operator are appropriate, nor can it tell if it has an update() method. Before writing, I had more-or-less co

Re: I'm missing something here...

2016-01-12 Thread Skip Montanaro
I created an issue for the pylint folks: https://github.com/PyCQA/pylint/issues/774 Skip -- https://mail.python.org/mailman/listinfo/python-list

Setting up/authenticating Google API?

2016-02-21 Thread Skip Montanaro
hers don't have the same problems I have. Thanks, Skip Montanaro -- https://mail.python.org/mailman/listinfo/python-list

Re: Setting up/authenticating Google API?

2016-02-24 Thread Skip Montanaro
> > Your question seems quite cinfusing to me but I think following may is what > you are asking for.(Read the source) > > https://google-mail-oauth2-tools.googlecode.com/svn/trunk/python/oauth2.py > > After getting the authentication you can use imaplib to get all the gmail > Data. Thanks, I wi

Continuing indentation

2016-03-02 Thread Skip Montanaro
Running flake8 over some code which has if statements with multiple conditions like this: if (some_condition and some_other_condition and some_final_condition): play_bingo() the tool complains that the indentation of the conditions is the same as the next block. In th

Re: Continuing indentation

2016-03-02 Thread Skip Montanaro
Thanks for the replies, folks. I'll provide a single response: 1. Using backslash to continue... When I first started using Python in the mid-90s I don't recall that parenthesized expressions could be continued across lines (at least, not in all contexts), so the backslash was required. I believe

Missing something about timezones

2016-03-14 Thread Skip Montanaro
Is this correct (today, with Daylight Savings in effect)? >>> import pytz >>> i.timezone 'America/Chicago' >>> pytz.timezone(i.timezone) >>> ot datetime.datetime(2016, 3, 14, 9, 30, tzinfo=) >>> ot.tzinfo Shouldn't the America/Chicago timezone reflect DST? Thx, Skip -- https://mail.python.or

Re: Missing something about timezones

2016-03-14 Thread Skip Montanaro
On Mon, Mar 14, 2016 at 10:26 AM, Ian Kelly wrote: > Why should it? You only asked pytz for the Chicago timezone. You > didn't ask for it relative to any specific time. Thanks. I thought using America/Chicago was supposed to automagically take into account transitions into and out of Daylight Sav

Re: Missing something about timezones

2016-03-14 Thread Skip Montanaro
On Mon, Mar 14, 2016 at 11:20 AM, Ian Kelly wrote: > Note that the above example is technically incorrect since > datetime.now() returns local time and I'm not in the Chicago timezone, > but it demonstrates the process. > > Also, if you haven't already read the pytz documentation, you should. > ht

Re: Truthiness

2014-10-23 Thread Skip Montanaro
On Thu, Oct 23, 2014 at 9:30 AM, Simon Kennedy wrote: > Just out of academic interest, is there somewhere in the Python docs where > the following is explained? Yes: https://docs.python.org/3/library/stdtypes.html#truth-value-testing https://docs.python.org/2.7/library/stdtypes.html#truth-valu

Re: support for boost::python for build double object

2014-11-03 Thread Skip Montanaro
On Mon, Nov 3, 2014 at 7:53 AM, Joseph Shen wrote: > In the boost::python library there is a function > > >>> boost::python::long_ > > and this function return a boost::python::object variable > > I'm trying to wrap a double variable but I can't find > something just like > > >> boost::python::d

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Skip Montanaro
On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez wrote: > The workaround of calling a different method inside __call__ is not valid > for my case because I want to change the *signature* of the function also > -for introspection reasons. You could define __call__ like so: def __call__(self, *a

Misunderstanding buffering - flushing isn't

2014-11-05 Thread Skip Montanaro
I've been developing a little web server. The request handler subclasses SimpleHTTPRequestHandler. It has a do_GET method which figures out what work to actually do, then ends with this: def do_GET(self): ... sys.stdout.flush() sys.stderr.flush() As it's still being ac

Re: Misunderstanding buffering - flushing isn't

2014-11-05 Thread Skip Montanaro
On Wed, Nov 5, 2014 at 10:44 AM, Skip Montanaro wrote: > I figured everything would be flushed to the respective .stdout and > .stderr files at the end of every request, but that appears not to be > the case. I stand corrected. I added print ">> request finished&qu

Re: Misunderstanding buffering - flushing isn't

2014-11-05 Thread Skip Montanaro
On Wed, Nov 5, 2014 at 11:29 AM, Irmen de Jong wrote: > Any reason you're not using the logging module and get it all nicely dumped > into a log > file instead? I'm an old fart. What can I say? BITD, (as Irmen is well aware, being about as old as I am in Python years), print was all we had. (We

Re: __missing__ for the top-level Python script

2014-11-12 Thread Skip Montanaro
> No bites? I'd have thought there'd be a few crazy ideas thrown out in > answer to this. I was on vacation for a few days, so haven't been all that attentive to my mail. I have an autoload module which does something similar (note the Python 2.x syntax): import sys, inspect, traceback, re def a

Re: __missing__ for the top-level Python script

2014-11-12 Thread Skip Montanaro
On Wed, Nov 12, 2014 at 12:49 PM, Chris Angelico wrote: > Interesting data point there - that you actually have it handy and > choose not to use it. And, I believe I wrote it. Can't have a worse recommendation than that. A cook who doesn't eat his own cooking. :-) I think I disabled its import so

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-12 Thread Skip Montanaro
> def main(func): > if func.__module__ == "__main__": > func() > return func # The return could be omitted to block the function from > being manually called after import. > > Just decorate the "main" function of the script with that, and it will be > automatically called when r

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-13 Thread Skip Montanaro
On Thu, Nov 13, 2014 at 2:33 PM, Ian Kelly wrote: > ... other things decorated with atexit.register > might actually be called before the main function I don't think that will happen. The atexit module is documented to execute its exit functions in reverse order. What's not documented is the beha

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-13 Thread Skip Montanaro
On Thu, Nov 13, 2014 at 2:44 PM, Skip Montanaro wrote: > What's not documented is > the behavior of calling atexit.register() while atexit._run_exitfuncs > is running. That's an implementation detail, and though unlikely to > change, it might be worthwhile getting that beha

Potential pitfalls when going from old-style to new-style classes

2014-11-19 Thread Skip Montanaro
I discussion on the code-quality list got me thinking. Suppose I have an old-style class in a 2.x app: class Foo: def __init__(self): blah blah blah I still use 2.x exclusively, but anytime I run pylint over a bit of code and it complains that Foo is old-school, I make the obvious change to

Re: Python docs disappointing

2014-11-20 Thread Skip Montanaro
On Thu, Nov 20, 2014 at 9:54 AM, wrote: > > Here is an *entirely typical* example: on some Unix, try > > > > % pydoc urllib > I don't know who "kj" is, and jstnms123 seems to be basically off his rocker, so I won't try cc'ing either of them. (They also seem to misunderstand the nature of contrib

RE: Comprehension with two variables - explanation needed

2014-11-23 Thread Skip Montanaro
> But it breaks all the picture that I've built in my head about comps till > now... Note that list comprehensions are little more than syntactic sugar for for loops. If you're having terrible writing or understanding one, especially a compound one like your example, it can help to write it as a (

Re: Comprehension with two variables - explanation needed

2014-11-23 Thread Skip Montanaro
On Sun, Nov 23, 2014 at 9:57 AM, Roy Smith wrote: > > If it was complicated enough that you needed to loopify it to > understand what it's doing, have pity on the next person who has to > maintain your code and leave it as a loop Well, sure. I was mostly trying to give Ivan a path out of the weed

Re: "**" in python

2014-11-23 Thread Skip Montanaro
I want to add one more thing to the other responses. People new to Python often seem unaware that being an interpreted language, often the best way to figure something out is to simply try it at the interpreter prompt. The OP saw "var ** 2" in done code. The most obvious thing to me would have been

Re: How to detect that a function argument is the default one

2014-12-10 Thread Skip Montanaro
On Wed, Dec 10, 2014 at 9:14 AM, ast wrote: > I have the idea to write: > > def __init__(center=(0,0), radius=10, mass=None)): > >if mass == None:self.mass = radius**2 >else: >self.mass = mass > > but maybe Python provides something clever. This is almost the correct idio

Re: how to delete my file if exits in the remote server with paramiko?

2014-12-14 Thread Skip Montanaro
On Sun, Dec 14, 2014 at 6:49 AM, 水静流深 <1248283...@qq.com> wrote: > Is there more elegant way to do the same work? Unlikely. You have two fairly simple bits of code in your example, one to connect to the remote server, the other to check for the file's existence and remove it. The only extra elegan

Re: Hello World

2014-12-22 Thread Skip Montanaro
On Mon, Dec 22, 2014 at 9:22 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > Don't try this at home! > > > # download_naked_pictures_of_jennifer_lawrence.py > import os > os.system("rm ――rf /") And because Steven *knows* some fool will "try this at home", he cripples the rm co

Re: is pathlib Path.resolve working as intended?

2014-12-24 Thread Skip Montanaro
>>> p.resolve() ... FileNotFoundError: [Errno 2] No such file or directory: '/Users/chris/~' I've not used the pathlib module yet, but poked through the documentation. Oddly enough, I saw no mention of "~". The doc for the resolve method only mentions resolving symlinks. In addition, the pathlib d

Re: If One Line

2014-12-25 Thread Skip Montanaro
I don't get an error. >>> I = 1 if True else 2 >>> if I == 1: print("one") ... one >>> What error did you get? Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: If One Line

2014-12-25 Thread Skip Montanaro
> Actually more that in the interpreter, it's prompting me with ... as if I had left out a closing ) or something, but, suppose it could work fine in an actual imported bit of code? That's how it's supposed to work. Given that Python block structure is determined by indentation, you need some way

Re: suggestions for VIN parsing

2014-12-25 Thread Skip Montanaro
You're extracting structured data from an html file. You might want to look at the lxml.etree module. (I think that's where ElementTree landed when it was adopted into the stdlib). Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: CSV Error

2014-12-28 Thread Skip Montanaro
> ValueError: I/O operation on closed file > > Here is my code in a Python shell - > > >>> with open('x.csv','rb') as f: > ... r = csv.DictReader(f,delimiter=",") > >>> r.fieldnames The file is only open during the context of the with statement. Indent the last line to match the assignment to

Re: CSV Error

2014-12-28 Thread Skip Montanaro
Hmmm... Works for me. % python Python 2.7.6+ (2.7:db842f730432, May 9 2014, 23:53:26) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> with open("coconutBattery.csv", "rb") as f: ... r = csv.DictReader(

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Skip Montanaro
> We were discussing something along these lines a while ago, and I > never saw anything truly satisfactory - there's no easy way to handle > a missing name by returning a value (comparably to __getattr__), you > have to catch it and then try to re-execute the failing code, which > isn't perfect. H

Re: CSV Dictionary

2014-12-29 Thread Skip Montanaro
On Mon, Dec 29, 2014 at 9:35 AM, JC wrote: > How could I get the all the records? This should work: with open('x.csv','rb') as f: rdr = csv.DictReader(f,delimiter=',') rows = list(rdr) You will be left with a list of dictionaries, one dict per row, keyed by the values in the first row:

Re: CSV Dictionary

2014-12-29 Thread Skip Montanaro
On Mon, Dec 29, 2014 at 10:11 AM, JC wrote: > Do I have to open the file again to get 'rdr' work again? Yes, but if you want the number of records, just operate on the rows list, e.g. len(rows). Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Why do the URLs of posts here change?

2015-01-09 Thread Skip Montanaro
> Posts on this newsgroup/mailing list are archived on the web, but the URLs > seem to change, which leaves dead links if you search for things. Steven, It's a known issue, but one which appears to be somewhat unavoidable, at least in Mailman 2.x. The problem is that every now and then, postmas..

Re: Why do the URLs of posts here change?

2015-01-09 Thread Skip Montanaro
On Fri, Jan 9, 2015 at 8:09 AM, Rustom Mody wrote: > Theres a new app/service that should solve your problem: > Its from google... and called groups > It solves one problem (moving archive URLs) by, I think, ignoring the other (archive posts which should really be removed). Skip -- https://ma

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-09 Thread Skip Montanaro
> I noticed in use that if an option with the 'append' action isn't > used, argparse assigns None to it rather than an empty list, & > confirmed this interactively: I don't use argparse (or optparse), being a getopt Luddite myself, but can you set the default for an action in the add_argument call

Re: Why do the URLs of posts here change?

2015-01-10 Thread Skip Montanaro
On Sat, Jan 10, 2015 at 3:41 AM, Terry Reedy wrote: > The post could be replaced by a placeholder "This message deleted' > > and the >> >> archive regenerated. That changes the counter for every message after > > > A placeholder should avoid that. I suspect (though don't know for certain) that j

Re: annoying doctest problem

2015-01-12 Thread Skip Montanaro
ISTR that when Tim Peters first implemented first, the typical way you were expected to get tests into a doc string was to copy from an interactive session, which would not have this problem. Also, to Steven's comment about fussiness, it isn't so much that it's fussy. It's more that it's dumb. I j

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