Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71854 > unrolled thread

All-numeric script names and import

Started byChris Angelico <rosuav@gmail.com>
First post2014-05-21 23:46 +1000
Last post2014-05-23 16:52 -0600
Articles 11 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  All-numeric script names and import Chris Angelico <rosuav@gmail.com> - 2014-05-21 23:46 +1000
    Re: All-numeric script names and import Mark H Harris <harrismh777@gmail.com> - 2014-05-21 09:24 -0500
      Re: All-numeric script names and import Chris Angelico <rosuav@gmail.com> - 2014-05-22 00:40 +1000
    Re: All-numeric script names and import Mark H Harris <harrismh777@gmail.com> - 2014-05-21 09:24 -0500
    Re: All-numeric script names and import Rustom Mody <rustompmody@gmail.com> - 2014-05-22 19:08 -0700
      Re: All-numeric script names and import Chris Angelico <rosuav@gmail.com> - 2014-05-23 13:26 +1000
      Re: All-numeric script names and import Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-05-23 10:58 +0200
      Re: All-numeric script names and import Chris Angelico <rosuav@gmail.com> - 2014-05-23 19:02 +1000
      Re: All-numeric script names and import Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-05-23 11:22 +0200
      Re: All-numeric script names and import Chris Angelico <rosuav@gmail.com> - 2014-05-23 19:28 +1000
      Re: All-numeric script names and import Michael Torrie <torriem@gmail.com> - 2014-05-23 16:52 -0600

#71854 — All-numeric script names and import

FromChris Angelico <rosuav@gmail.com>
Date2014-05-21 23:46 +1000
SubjectAll-numeric script names and import
Message-ID<mailman.10190.1400680014.18130.python-list@python.org>
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

[toc] | [next] | [standalone]


#71856

FromMark H Harris <harrismh777@gmail.com>
Date2014-05-21 09:24 -0500
Message-ID<537CB71E.5060506@gmail.com>
In reply to#71854
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

[toc] | [prev] | [next] | [standalone]


#71859

FromChris Angelico <rosuav@gmail.com>
Date2014-05-22 00:40 +1000
Message-ID<mailman.10194.1400683267.18130.python-list@python.org>
In reply to#71856
On Thu, May 22, 2014 at 12:24 AM, Mark H Harris <harrismh777@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

[toc] | [prev] | [next] | [standalone]


#71863

FromMark H Harris <harrismh777@gmail.com>
Date2014-05-21 09:24 -0500
Message-ID<mailman.10198.1400684322.18130.python-list@python.org>
In reply to#71854
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

[toc] | [prev] | [next] | [standalone]


#71915

FromRustom Mody <rustompmody@gmail.com>
Date2014-05-22 19:08 -0700
Message-ID<1714fbce-827f-4ba5-853c-f2f934a75466@googlegroups.com>
In reply to#71854
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

[toc] | [prev] | [next] | [standalone]


#71916

FromChris Angelico <rosuav@gmail.com>
Date2014-05-23 13:26 +1000
Message-ID<mailman.10233.1400816037.18130.python-list@python.org>
In reply to#71915
On Fri, May 23, 2014 at 12:08 PM, Rustom Mody <rustompmody@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

[toc] | [prev] | [next] | [standalone]


#71918

FromWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Date2014-05-23 10:58 +0200
Message-ID<mailman.10235.1400835559.18130.python-list@python.org>
In reply to#71915
On 23.05.2014 05:26, Chris Angelico wrote:
> On Fri, May 23, 2014 at 12:08 PM, Rustom Mody <rustompmody@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

[toc] | [prev] | [next] | [standalone]


#71919

FromChris Angelico <rosuav@gmail.com>
Date2014-05-23 19:02 +1000
Message-ID<mailman.10236.1400835737.18130.python-list@python.org>
In reply to#71915
On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier
<wolfgang.maier@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

[toc] | [prev] | [next] | [standalone]


#71920

FromWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Date2014-05-23 11:22 +0200
Message-ID<mailman.10237.1400836971.18130.python-list@python.org>
In reply to#71915
On 23.05.2014 11:02, Chris Angelico wrote:
> On Fri, May 23, 2014 at 6:58 PM, Wolfgang Maier
> <wolfgang.maier@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

[toc] | [prev] | [next] | [standalone]


#71921

FromChris Angelico <rosuav@gmail.com>
Date2014-05-23 19:28 +1000
Message-ID<mailman.10238.1400837363.18130.python-list@python.org>
In reply to#71915
On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier
<wolfgang.maier@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

[toc] | [prev] | [next] | [standalone]


#71945

FromMichael Torrie <torriem@gmail.com>
Date2014-05-23 16:52 -0600
Message-ID<mailman.10256.1400885551.18130.python-list@python.org>
In reply to#71915
On 05/23/2014 03:28 AM, Chris Angelico wrote:
> On Fri, May 23, 2014 at 7:22 PM, Wolfgang Maier
> <wolfgang.maier@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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web