Re: All-numeric script names and import
On 23.05.2014 05:26, Chris Angelico wrote: On Fri, May 23, 2014 at 12:08 PM, Rustom Mody rustompm...@gmail.com 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/mailman/listinfo/python-list
Re: All-numeric script names and import
On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de 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/listinfo/python-list
Re: All-numeric script names and import
On 23.05.2014 11:02, Chris Angelico wrote: On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de 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! :) 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 :) Cheers, Wolfgang -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de 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 strikes me as a very dangerous proposal. Imagine what would happen when you try to import chip in New Zealand and it goes out looking for chup.py. Or the devastating results of yes.py and no.py being indistinguishable on politicians' builds of Python... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On 05/23/2014 03:28 AM, Chris Angelico wrote: On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de 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 strikes me as a very dangerous proposal. Imagine what would happen when you try to import chip in New Zealand and it goes out looking for chup.py. Or the devastating results of yes.py and no.py being indistinguishable on politicians' builds of Python... If you use a proper web framework, then you can define your urls to be anything you want. Just set up the appropriate mapping and away you go. Furthermore you can use apache directives to alias /1/ to something more importable. -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
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 the moment), but not with the statement form. # 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 that last question. Yes is a perfectly acceptable answer. But please explain which of the several possibilities is the way I'm being dumb. Thanks!) ChrisA 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__'] Xavier -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
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 not remove the builtins and should add __file__. With corrections: import imp module_1 = imp.new_module('module_1') execfile('1.py', module_1.__dict__) module_1.__file__ = '1.py' Xavier -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On Thu, May 22, 2014 at 8:32 PM, Xavier de Gaye xdeg...@gmail.com 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 __import__() is simpler than that :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
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 working on, at least for the moment), but not with the statement form. $ cat ا.py x = 1 def foo(x): print(Hi %s!! % x) $ python3 Python 3.3.5 (default, Mar 22 2014, 13:24:53) [GCC 4.8.2] on linux Type help, copyright, credits or license for more information. import ا ا.foo('Chris') Hi Chris!! ا.x 1 -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On Fri, May 23, 2014 at 12:08 PM, Rustom Mody rustompm...@gmail.com 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
All-numeric script names and import
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 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 that last question. Yes is a perfectly acceptable answer. But please explain which of the several possibilities is the way I'm being dumb. Thanks!) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
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 that last question. Yes is a perfectly acceptable answer. But please explain which of the several possibilities is the way I'm being dumb. Thanks!) If you have a script that is self-programming (producing sequenced, numbered scripts 1.py 2.py 3.py) then why not just prefix an alpha character a1.py a2.py a3.py ? Otherwise, are you just pulling our chain?:) 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. Why must you have a numbered script? You're just pulling someone's chain, right? marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On Thu, May 22, 2014 at 12:24 AM, Mark H Harris harrismh...@gmail.com 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, just not importably. Why must you have a numbered script? You're just pulling someone's chain, right? Heh. No, I'm actually finally getting around to rewriting something in Python. It's been called 1 for as long as it's ever existed, having made the jump from a flat file in my personal directory to a web site, and since then from MySQL to PostgreSQL, and finally now I'm getting rid of the last artefact of the old web host by ditching PHP. Yes, I wrote it in PHP because it was hosted on a server that didn't support Python, and when I moved everything onto my own server, I didn't rewrite it. But that's no excuse for changing the name now :) http://rosuav.com/1/ Now, I could of course rename the .py files while still having it at /1/ on the site, but that's cheating. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
On Thu, May 22, 2014 at 12:32 AM, Dave Angel da...@davea.name 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 (you can't go 1 = 2 because 1 isn't a name). In some contexts you can force a different interpretation, so for instance you can look at attributes of an integer literal as (1).real even though 1.real is an error; but I couldn't find a way to fiddle this one. And the only way I could find to pass a string was to use __import__(). So is that the only way? Same thing would happen, I guess, if you have dots in the file name. A file called foo.bar.py probably can't be imported. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: All-numeric script names and import
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. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list