Re: All-numeric script names and import

2014-05-23 Thread Michael Torrie
On 05/23/2014 03:28 AM, Chris Angelico wrote: > On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier > wrote: >> I see, so what you should propose then is a change to import, so that when >> it can't find a module it will try to import an alternative that's >> pronounced the same way. Then you could si

Re: All-numeric script names and import

2014-05-23 Thread Chris Angelico
On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier wrote: > I see, so what you should propose then is a change to import, so that when > it can't find a module it will try to import an alternative that's > pronounced the same way. Then you could simply do: > > import one > > and you're fine :) This

Re: All-numeric script names and import

2014-05-23 Thread Wolfgang Maier
On 23.05.2014 11:02, Chris Angelico wrote: On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier wrote: Latin, you DID use Arabic numbers :) I may have used an Arabic numeral, but I named my script very definitely in English. Isn't it obvious? It's read "one dot pie", which is clearly English! :)

Re: All-numeric script names and import

2014-05-23 Thread Chris Angelico
On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier wrote: > Latin, you DID use Arabic numbers :) > I may have used an Arabic numeral, but I named my script very definitely in English. Isn't it obvious? It's read "one dot pie", which is clearly English! :) ChrisA -- https://mail.python.org/mailman/

Re: All-numeric script names and import

2014-05-23 Thread Wolfgang Maier
On 23.05.2014 05:26, Chris Angelico wrote: On Fri, May 23, 2014 at 12:08 PM, Rustom Mody wrote: $ cat ا.py x = 1 def foo(x): print("Hi %s!!" % x) Yeah, no thanks. I am not naming my scripts in Arabic. :) Latin, you DID use Arabic numbers :) Cheers, Wolfgang -- https://mail.python.org/mai

Re: All-numeric script names and import

2014-05-22 Thread Chris Angelico
On Fri, May 23, 2014 at 12:08 PM, Rustom Mody wrote: > $ cat ا.py > x = 1 > def foo(x): print("Hi %s!!" % x) Yeah, no thanks. I am not naming my scripts in Arabic. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: All-numeric script names and import

2014-05-22 Thread Rustom Mody
On Wednesday, May 21, 2014 7:16:46 PM UTC+5:30, Chris Angelico wrote: > If I have a file called 1.py, is there a way to import it? Obviously I > can't import it as itself, but in theory, it should be possible to > import something from it. I can manage it with __import__ (this is > Python 2.7 I'm w

Re: All-numeric script names and import

2014-05-22 Thread Chris Angelico
On Thu, May 22, 2014 at 8:32 PM, Xavier de Gaye wrote: > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in > sys.modules): > import imp module_1 = imp.new_module('module_1') execfile('1.py', module_1.__dict__) del module_1.__dict__['__builtins__'] Heh, I think

Re: All-numeric script names and import

2014-05-22 Thread Xavier de Gaye
On 05/22/2014 12:32 PM, Xavier de Gaye wrote: > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in sys.modules): > > >>> import imp > >>> module_1 = imp.new_module('module_1') > >>> execfile('1.py', module_1.__dict__) > >>> del module_1.__dict__['__builtins__'] Oups.. should

Re: All-numeric script names and import

2014-05-22 Thread Xavier de Gaye
On 05/21/2014 03:46 PM, Chris Angelico wrote: > If I have a file called 1.py, is there a way to import it? Obviously I > can't import it as itself, but in theory, it should be possible to > import something from it. I can manage it with __import__ (this is > Python 2.7 I'm working on, at least for

Re: All-numeric script names and import

2014-05-21 Thread Ethan Furman
On 05/21/2014 06:46 AM, Chris Angelico wrote: # from 1 import app as application # Doesn't work with a numeric name application = __import__("1").app The statement form of import only works with valid Python identifiers. So all numeric names won't work, names with dashes won't work, etc. -

Re: All-numeric script names and import

2014-05-21 Thread Chris Angelico
On Thu, May 22, 2014 at 12:32 AM, Dave Angel wrote: > I don't think there's any question of dumbhood, but the answer > should be found in the formal grammar document. Yeah, I figured it'd be an issue of the grammar. It expects 1 to mean an integer, not a name - which in most contexts is correct

Re: All-numeric script names and import

2014-05-21 Thread Chris Angelico
On Thu, May 22, 2014 at 12:24 AM, Mark H Harris wrote: > On the other hand, if you open IDLE and then open the 1.py module (yes, > that's a dumb name) and then click run--> run module it will import and > run... assuming 1.py contains some valid python code. Oh, it runs fine as an application,

Re: All-numeric script names and import

2014-05-21 Thread Mark H Harris
On 5/21/14 8:46 AM, Chris Angelico wrote: # from 1 import app as application # Doesn't work with a numeric name application = __import__("1").app Is there a way to tell Python that, syntactically, this thing that looks like a number is really a name? Or am I just being dumb? (Don't hold back on

All-numeric script names and import

2014-05-21 Thread Chris Angelico
If I have a file called 1.py, is there a way to import it? Obviously I can't import it as itself, but in theory, it should be possible to import something from it. I can manage it with __import__ (this is Python 2.7 I'm working on, at least for the moment), but not with the statement form. # from