Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Chris Angelico
On Fri, Oct 22, 2021 at 10:36 PM Antoon Pardon wrote: > > I have a file with python code but the name doesn't end with the '.py' > suffix. > > What is the easiest way to import this code as a module without changing > its name? > It should be possible to use importlib for this: https://docs.pyth

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Chris Johns
The (newer) risc os port does a whole bunch of stuff in importlib to do this, as it natively doesn’t use extensions but file types. I’m not sure if you could do something similar without modifying importlib and re-freezing it. https://github.com/c-jo/cpython/blob/riscos-310/Lib/importlib/_boots

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Rob Cliffe via Python-list
As far as I know, it can't be done. If I was REALLY desperate I might try (tested) import os os.rename('myfile.myext', 'myfile.py') import myfile os.rename('myfile.py', 'myfile.myext') # with appropriate modifications if myfile is not in the current directory but this is a horrible solution, sub

Re: Importing modules with arguments

2021-07-30 Thread Chris Angelico
On Sat, Jul 31, 2021 at 5:11 AM Charles Smith wrote: > > First off, thanks for the answer. I don't see the cached module as a problem > here. If you provide arguments to a module, the goal is "most likely" to > alter/parameterize the behavior of the first import. Now, I agree that > behavior be

Re: Importing modules with arguments

2021-07-30 Thread Charles Smith
First off, thanks for the answer. I don't see the cached module as a problem here. If you provide arguments to a module, the goal is "most likely" to alter/parameterize the behavior of the first import. Now, I agree that behavior becomes unpredictable because passing different parameters on subs

Re: Importing modules with arguments

2021-07-30 Thread Chris Angelico
On Sat, Jul 31, 2021 at 3:48 AM Charles Smith wrote: > > I have found myself wanting to import module and provide arguments to them. > There's two main reason I could think of for this. First is to prevent a > circular import, though most of circular imports can be prevented by changing > the d

Re: Importing from within package

2020-09-23 Thread Abdur-Rahmaan Janhangeer
Thanks for the lead. Checking tomorrow! If so i'll have to include other folders as well ... Kind Regards, Abdur-Rahmaan Janhangeer https://www.github.com/Abdur-RahmaanJ Mauritius sent from gmail client on Android, that's why the signature is so ugly. -- https://mail.python.org/mailman/listi

Re: Importing from within package

2020-09-23 Thread Dieter Maurer
Abdur-Rahmaan Janhangeer wrote at 2020-9-23 22:41 +0400: >In shopyo/shopyo (the same folder as __main__.py) there is a folder called >shopyoapi. Not in the distribution: ... shopyo-1.1.45/shopyo/ shopyo-1.1.45/shopyo/__init__.py shopyo-1.1.45/shopyo/__main__.py shopyo-1.1.45/shopyo/app.py shopyo-1

Re: Importing from within package

2020-09-23 Thread Abdur-Rahmaan Janhangeer
In shopyo/shopyo (the same folder as __main__.py) there is a folder called shopyoapi. What i want is to import create_module from cmd.py from shopyoapi in __main__.py but it does not work or more precisely i am looking how to make it work! Since this is not py2 i guess no init needed in shopyoapi

Re: Importing from within package

2020-09-23 Thread Dieter Maurer
Abdur-Rahmaan Janhangeer wrote at 2020-9-22 20:14 +0400: >I have this main script: >https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py > >However, i get errors after package installation >saying: >ImportError: cannot import name 'shopyoapi' from 'shopyo' It is right: `shopyyoapi`

Re: Importing from within package

2020-09-22 Thread Abdur-Rahmaan Janhangeer
Greetings list, In case this might help, i am on Python3.8 and running in a virtual env This command also does not work: python -m shopyo new . test2 Kind Regards, Abdur-Rahmaan Janhangeer about | blog github

Re: Importing from within package

2020-09-22 Thread Chris Angelico
On Wed, Sep 23, 2020 at 2:16 PM Terry Reedy wrote: > > On 9/22/2020 8:31 PM, Chris Angelico wrote: > > On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber > > wrote: > >> > >> On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer > >> declaimed the following: > >> > >>> I have this main sc

Re: Importing from within package

2020-09-22 Thread Terry Reedy
On 9/22/2020 8:31 PM, Chris Angelico wrote: On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber wrote: On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer declaimed the following: I have this main script: https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py

Re: Importing from within package

2020-09-22 Thread 黃炳熙
Chris Angelico writes: > ... > In a package, __main__.py does that same job. Sorry ChrisA, would you please some example? Because i am working in progress with Python things... Sicnerely, Byung-Hee -- ^고맙습니다 _布德天下_ 감사합니다_^))// -- https://mail.python.org/mailman/listinfo/python-list

Re: Importing from within package

2020-09-22 Thread Chris Angelico
On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber wrote: > > On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer > declaimed the following: > > >I have this main script: > >https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py > > > > Well, that file name scares me

Re: Importing module from another subdirectory

2019-04-25 Thread Rich Shepard
On Thu, 25 Apr 2019, dieter wrote: The means that "test_act_de.py" has not extended "sys.path" appropriately. Dieter, That's what I thought. When Python starts a script ("gui/test_act_de.py" in your case), it automatically extends "sys.path" with the folder containing the script ("gui" in y

Re: Importing module from another subdirectory

2019-04-24 Thread dieter
Rich Shepard writes: >> bustrac/ >>README.rst >>bustrac.py* >>controller/ >>classes/ > model.py >>scripts/ >>gui/ > test_act_de.py > > test_act_de.py tries to import model.py from the classes package: > from classes import model as m > > Running in bustrac

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, Rich Shepard wrote: The current project's directory structure is: I changed package names so there are no duplicate names for packages and modules. bustrac/ README.rst bustrac.py* controller/ classes/ model.py scripts/ gui/ test_act

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, Rich Shepard wrote: If I correctly understand the process, in bustrac.py I'll add import sys.path sys.path.append(controller, model, scripts, views) Never mind. I've installed virtualenv and will work within it. Regards, Rich -- https://mail.python.org/mailman/listinfo/p

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, dieter wrote: With a "virtualenv", there is usually no need to tweak "sys.path" -- you simply install everything your project needs into the "virtualenv". Dieter, Okay. I just upgraded pip to 19.1 for python3 and virtualenv to version 16.5.0. Now I'll learn how to use it

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, dieter wrote: "sys.path" tweaks are typically employed with a "central" Python installation, to have it look at non-standard places for module/packages under specific circumstances. Almost all python packages installed here are built using the SlackBuilds.org scripts (I ru

Re: Importing module from another subdirectory

2019-04-23 Thread dieter
Rich Shepard writes: > On Tue, 23 Apr 2019, dieter wrote: > ... > One project is for my own use and I understand now that a virtualenv with > its own sys.path appendices would work. Those are two separate approaches: With a "virtualenv", there is usually no need to tweak "sys.path" -- you simply

Re: Importing module from another subdirectory

2019-04-23 Thread Rich Shepard
On Tue, 23 Apr 2019, dieter wrote: I use "virtualenv" (for "VIRTUAL ENVironmet") to separate projects. Dieter, I know about virtualenv and tried using them. Found conflicting information and didn't know if I really needed them. I'll re-learn how to activate and use them. One project is for m

Re: Importing module from another subdirectory

2019-04-22 Thread dieter
Rich Shepard writes: > On Thu, 18 Apr 2019, dieter wrote: > ... >> 2. extend "sys.path" in your scripts to contain the "bustrac" folder >> (before you try to import infrastructure modules/packages) > > I read the docs for sys and site and have insufficient experience with them > to know how best t

Re: Importing module from another subdirectory

2019-04-22 Thread Rich Shepard
On Thu, 18 Apr 2019, dieter wrote: I see two options for you: 1. put your scripts directly into "bustrac" (rather than a subdirectory) There are too many files; the directory is very cluttered. 2. extend "sys.path" in your scripts to contain the "bustrac" folder (before you try to import in

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Thu, 18 Apr 2019, dieter wrote: Python knows about 2 kinds of "regular" imports: absolute ones and relative ones. "Absolute" imports are guided by "sys.path" -- in the simple case, a sequence of folders containing modules and/or pacakges. Relative imports are guided in a similar way by the cu

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Wed, 17 Apr 2019, Sayth Renshaw wrote: Apologies I don't know the answer but went looking. This guide should answer the question. Didn't know it was so difficult to be honest. https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#example-directory-structure Then there

Re: Importing module from another subdirectory

2019-04-17 Thread dieter
Rich Shepard writes: > What is the proper syntax to import the model class in the model/ > subdirectory into a tkinter view module, e.g., activities.py? The syntax, > 'import model as m' fails because it is not in the same subdirectory as the > importing module. > > The program directory tree is:

Re: Importing module from another subdirectory

2019-04-17 Thread Sayth Renshaw
On Thursday, 18 April 2019 06:59:43 UTC+10, Rich Shepard wrote: > What is the proper syntax to import the model class in the model/ > subdirectory into a tkinter view module, e.g., activities.py? The syntax, > 'import model as m' fails because it is not in the same subdirectory as the > importing

Re: Importing with ctypes in Python: fighting overflows

2017-03-07 Thread eryk sun
On Tue, Mar 7, 2017 at 12:45 PM, wrote: > Importing with ctypes in Python: fighting overflows: > https://www.cossacklabs.com/blog/fighting-ctypes-overflows.html C int is 32-bit on all platforms currently supported by CPython -- both 32-bit and 64-bit. It's the default result type and the default

Re: importing down in code rather than at top of file.

2016-08-30 Thread dieter
Tobiah writes: > Is it worth while to defer the import of a large module that seldom > gets used in the script? > > > import sys > import os > > if hardly_ever_happens(): > > import large_module > large_module.do_task() I have used de

Re: importing down in code rather than at top of file.

2016-08-29 Thread Terry Reedy
On 8/29/2016 1:57 PM, Tobiah wrote: Is it worth while to defer the import of a large module that seldom gets used in the script? import sys import os if hardly_ever_happens(): import large_module large_module.do_task() I imagine it takes a certain amount of pro

Re: importing down in code rather than at top of file.

2016-08-29 Thread Nobody
On Tue, 30 Aug 2016 04:15:05 +1000, Chris Angelico wrote: > Don't imagine; test. Testing alone isn't really good enough. There may be perfectly valid reasons to avoid the import which won't show up in anything less than the most thorough testing imaginable. Personally I wouldn't defer an import

Re: importing down in code rather than at top of file.

2016-08-29 Thread alister
On Mon, 29 Aug 2016 10:57:22 -0700, Tobiah wrote: > Is it worth while to defer the import of a large module that seldom > gets used in the script? > > > import sys import os > > if hardly_ever_happens(): > > import large_module large_module.do_task() >

Re: importing down in code rather than at top of file.

2016-08-29 Thread Chris Angelico
On Tue, Aug 30, 2016 at 3:57 AM, Tobiah wrote: > Is it worth while to defer the import of a large module that seldom > gets used in the script? > > > import sys > import os > > if hardly_ever_happens(): > > import large_module > large_module

Re: Importing from __future__ doesn't work under PDB

2016-05-11 Thread martin846
Many thanks for the quick reply. I must admit I was surprised not to find any note about this anywhere in the docs (or indeed anywhere online); it seems like something that people would have run into before. I've added a request to the documentation tracker to have a note added to help people wh

Re: Importing from __future__ doesn't work under PDB

2016-05-11 Thread Chris Angelico
On Wed, May 11, 2016 at 7:52 PM, wrote: > In other words, I get different results for the same expression (2/3) in the > program and on the pdb prompt, which makes debugging tricky. I cannot figure > out how to persuade pdb to actually load the division module. Is there an > approved way? Norm

Re: importing

2016-03-07 Thread Terry Reedy
On 3/7/2016 12:23 PM, Tony van der Hoff wrote: However, more generally, how am I supposed to know that a module is part of a package, and needs a "magic" stanza to get a module loaded? The doc for a package usually mentions the submodules it contains, as in https://docs.python.org/3/library/tk

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 20:07, MRAB wrote: On 2016-03-07 19:08, Mark Lawrence wrote: On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrot

Re: importing

2016-03-07 Thread MRAB
On 2016-03-07 19:08, Mark Lawrence wrote: On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tel

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make somet

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 10:23 AM, Tony van der Hoff wrote: > However, more generally, how am I supposed to know that a module is part of > a package, and needs a "magic" stanza to get a module loaded? If the import path of the module has a dot in it, then it's part of a package. -- https://mail.p

Re: importing

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: > Thanks to all who replied to my cry for help; I understand it better now. > But: > > On 07/03/16 16:08, Chris Angelico wrote: >> >> >> The documentation should tell you what you need to import to make >> something work. In this case, I wou

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 17:23, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make something work. In this case, I would guess that "import tkint

Re: importing

2016-03-07 Thread Tony van der Hoff
Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make something work. In this case, I would guess that "import tkinter.messagebox" or "from tkinter import message

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 15:54, Tony van der Hoff wrote: I thought I understood this, but apparently not: Under py3: 1. "import tkinter" imports the whole module into the name space. Any access to names therein must be prefixed with the module name. ie top = tkinter.Tk() But tkinter.messagebox.showwarning(

Re: importing

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 2:54 AM, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any access > to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 8:54 AM, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any access > to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.

Re: importing

2016-03-07 Thread Tim Golden
On 07/03/2016 15:54, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any > access to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.messagebox.

Re: Importing two modules of same name

2016-02-10 Thread Tim Johnson
* dieter [160209 23:03]: > Carl Meyer writes: > > ... > > If you omit the future-import in Python 2.7, `import config` will import > > the neighboring app/config.py by default, and there is no way to import > > the top-level config.py. > > There is the "__import__" builtin function which allows

Re: Importing two modules of same name

2016-02-09 Thread dieter
Carl Meyer writes: > ... > If you omit the future-import in Python 2.7, `import config` will import > the neighboring app/config.py by default, and there is no way to import > the top-level config.py. There is the "__import__" builtin function which allows to specify the "parent package" indirect

Re: Importing two modules of same name

2016-02-09 Thread Tim Johnson
* Carl Meyer [160209 15:28]: > Hi Tim, <...> > The proper way to do this in Python 2.7 is to place `from __future__ > import absolute_import` at the top of flask/app/__init__.py (maybe best > at the top of every Python file in your project, to keep the behavior > consistent). Once you have that f

Re: Importing two modules of same name

2016-02-09 Thread Carl Meyer
Hi Tim, On 02/09/2016 04:23 PM, Tim Johnson wrote: > Before proceding, let me state that this is to satisfy my > curiousity, not to solve any problem I am having. > > Scenario : > Web application developed at /some/dir/sites/flask/ > > If I have a package - let us call it app and in my > /some/d

Re: importing: what does "from" do?

2016-01-21 Thread Rustom Mody
On Thursday, January 21, 2016 at 7:53:07 PM UTC+5:30, Charles T. Smith wrote: > What does "from (module) import (func)" do? > > Please don't tell me that I shouldn't ask because real programmers > know not to have circular dependencies ... > > I have no idea what was imported before. I just want

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 16:30:30 +, Charles T. Smith wrote: >> Side observation: 'int' is a bad name for a package, because it will >> shadow the name of the 'int' built-in. > > > Boy oh boy have I experienced that now! :) (it wasn't me! ;) ) -- https://mail.python.org/mailman/listinfo/python

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 08:59:39 -0700, Ian Kelly wrote: > What happens if you just do 'import utilities'. Can you then call > utilities.hexdump? Can you see anything in the utilities module? Yes, that works! That's what I'm doing as a work around. I was trying to avoid doing that because I figured

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 02:53 am, Charles T. Smith wrote: > What I need is tools to find the problems. In particular, why doesn't > python give me more of a clue where the problem is? It would be cool > if it would tell me exactly what module to look at, which symbol(s) > were colliding. The proble

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 02:12 am, Charles T. Smith wrote: > On Thu, 21 Jan 2016 07:52:17 -0700, Ian Kelly wrote: > >>> I have no idea what was imported before. I just want to import >>> hexdump(). Unfortunately, this does not work: >>> >>> from utilities import hexdump >>> >>> ImportError: can

Re: importing: what does "from" do?

2016-01-21 Thread Ian Kelly
On Thu, Jan 21, 2016 at 8:12 AM, Charles T. Smith wrote: >>> would you explain to me why I get this: >>> >>> (PDB)hexdump(msg) >>> *** NameError: name 'hexdump' is not defined >> >> Probably because the name 'hexdump' is not defined. > > > If indeed it's not defined, then I wouldn't think there'

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > > How did this error come up? Did the code work previously? If so, what > > changed? > The developers of this legacy code had this as well as other functions > duplicated throughout the system, in order to avoid confronting these > issues. Yes, but did the co

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > In that case, the problem is most likely a circular import issue, as you > mentioned. The only way to fix it is to reorganize your modules. > > How did this error come up? Did the code work previously? If so, what > changed? What I nee

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > How did this error come up? Did the code work previously? If so, what > changed? The developers of this legacy code had this as well as other functions duplicated throughout the system, in order to avoid confronting these issues. I'm tr

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:31:45 +, John Gordon wrote: > The most likely explanation here is that the 'utilities' module simply > does not contain something named 'hexdump'. > > Have you inspected the 'utilities' module? Does it, in fact, contain > something named 'hexdump'? Yes -- https://ma

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > > The most likely explanation here is that the 'utilities' module simply > > does not contain something named 'hexdump'. > > > > Have you inspected the 'utilities' module? Does it, in fact, contain > > something named 'hexdump'? > Yes In that case, the proble

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > from utilities import hexdump > ImportError: cannot import name hexdump The most likely explanation here is that the 'utilities' module simply does not contain something named 'hexdump'. Have you inspected the 'utilities' module? Does it, in fact, conta

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 07:52:17 -0700, Ian Kelly wrote: >> I have no idea what was imported before. I just want to import >> hexdump(). Unfortunately, this does not work: >> >> from utilities import hexdump >> >> ImportError: cannot import name hexdump > > What is utilities? Is it a module on

Re: importing: what does "from" do?

2016-01-21 Thread Ian Kelly
On Jan 21, 2016 7:31 AM, "Charles T. Smith" wrote: > > What does "from (module) import (func)" do? Approximately equivalent to: import module func = module.func Except that it doesn't bind "module" to anything. > Please don't tell me that I shouldn't ask because real programmers > know not to

Re: Importing constantly changing variables

2015-12-26 Thread Ben Finney
ariklapid.s...@gmail.com writes: > Hello everyone ! > First of all, excuse me for my horrible English. As is often the case with people who make this apology, your English is far better than most native English speakers can use any other language :-) > A file named "sensors.py" imports varying v

Re: Importing constantly changing variables

2015-12-26 Thread Ian Kelly
On Sat, Dec 26, 2015 at 8:14 AM, wrote: > As you can see, I want the program to print all values each 5 seconds. > When I run the file "main.py" it does print values every 5 seconds, BUT when > I manually change > the values (e.g. airTemperture = 30 instead of 24) and save the file, nothing > c

Re: Importing is partially working...

2015-08-10 Thread Dwight GoldWinde
Such a simple change, I wouldn¹t think it would work. But it did. You suggested "from Functions import humprint² instead of "from Functions.py import humprint². Thank you, Chris! Now I can define functions all over the place. LOLŠ BIG SMILE... Always, Dwight www.3forliving.key.to (video p

Re: Importing is partially working...

2015-08-10 Thread Steven D'Aprano
On Tue, 11 Aug 2015 01:48 am, MRAB wrote: > On Windows, the extension for Python extension DLLs is ".pyd". I believe that there is a subtle difference in the entry-point depending on whether the file is named .pyd or .dll. http://effbot.org/pyfaq/is-a-pyd-file-the-same-as-a-dll.htm https://docs.

Re: Importing is partially working...

2015-08-10 Thread Chris Angelico
On Tue, Aug 11, 2015 at 1:48 AM, MRAB wrote: >> You're almost there! But in Python, you don't import something from a >> specific file - you import from a module, and the Python interpreter >> is free to locate that file anywhere that it can. It might be >> implemented in C, and be stored in Funct

Re: Importing is partially working...

2015-08-10 Thread MRAB
On 2015-08-10 11:11, Chris Angelico wrote: On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde wrote: name = 'Jim' coach = 'Dwight' import importlib sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be your coach today.' from Functions.py import humprint humprint (sentence) Tr

Re: Importing is partially working...

2015-08-10 Thread Chris Angelico
On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde wrote: > name = 'Jim' > coach = 'Dwight' > import importlib > sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be > your coach today.' > from Functions.py import humprint > humprint (sentence) > > Traceback (most recent call las

Re: Importing/migrating Mailman mbox files into Google Groups?

2015-04-18 Thread Skip Montanaro
On Sat, Apr 18, 2015 at 6:42 PM, Cameron Simpson wrote: > I think I understood that there was an existing archive. My caveat was more > something to consider before choosing GGroups (too late, and in any case > hardly a deal breaker, especially since Google finally cleaned up a lot of > their HTML

Re: Importing/migrating Mailman mbox files into Google Groups?

2015-04-18 Thread Cameron Simpson
On 18Apr2015 07:50, Skip Montanaro wrote: On Fri, Apr 17, 2015 at 7:33 PM, Cameron Simpson wrote: However, before you get very excited see if people can get messages back out of the archive. A major annoyance for me with GGroups versus mailman is that if I join a group I cannot download the hi

Re: Importing/migrating Mailman mbox files into Google Groups?

2015-04-18 Thread Skip Montanaro
On Fri, Apr 17, 2015 at 7:33 PM, Cameron Simpson wrote: > However, before you get very excited see if people can get messages back out > of the archive. A major annoyance for me with GGroups versus mailman is that > if I join a group I cannot download the historical archive. (This is a > standard

Re: Importing/migrating Mailman mbox files into Google Groups?

2015-04-17 Thread Cameron Simpson
On 16Apr2015 08:32, Skip Montanaro wrote: Quite sometime ago (2011?), the classic-rendezvous mailing list, which had been hosted by a Mailman instance at bikelist.org, was reconstituted as a Google Group. Just a bunch of old bikies interested in vintage bikes. The original archives were never im

Re: importing os.path -- why does it work?

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 23:00:45 -0700, Ian Kelly wrote: > On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano > wrote: >> But bizarrely, you can import os.path this way! >> >> py> import os.path >> py> os.path >> py> >> os.__package__ >> '' >> >> >> >> By what wizardry does this work? > > By the wiz

Re: importing os.path -- why does it work?

2015-01-11 Thread Ian Kelly
On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano wrote: > But bizarrely, you can import os.path this way! > > py> import os.path > py> os.path > > py> os.__package__ > '' > > > > By what wizardry does this work? By the wizardry of adding an entry to sys.modules. https://hg.python.org/cpython/f

Re: Importing by file name

2013-11-24 Thread Mark Lawrence
On 24/11/2013 14:15, Steven D'Aprano wrote: That was the case up to 3.3, but Python 3.4 has the import machinery re- written in pure Python (except for a tiny bit of bootstrapping machinery, if I understand correctly). I understand that nobody understood the import machinery in full (although th

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:15 AM, Steven D'Aprano wrote: > On Sun, 24 Nov 2013 19:07:38 +1100, Chris Angelico wrote: > >> I know the recent Pythons give a lot of import power to the script. But >> maybe I'm just asking too much, and some of this stuff really is magical >> and implemented in C? > >

Re: Importing by file name

2013-11-24 Thread Steven D'Aprano
On Sun, 24 Nov 2013 19:07:38 +1100, Chris Angelico wrote: > I know the recent Pythons give a lot of import power to the script. But > maybe I'm just asking too much, and some of this stuff really is magical > and implemented in C? That was the case up to 3.3, but Python 3.4 has the import machine

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Sun, Nov 24, 2013 at 4:05 AM, Chris Angelico wrote: > Undocumented... that explains why I didn't know about it! But that > does appear to be what I'm looking for, so is there some equivalent > planned as a replacement? Hmm, playing around with importlib a bit, this seems to work: from importl

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Sun, Nov 24, 2013 at 8:50 PM, Ian Kelly wrote: > On Sun, Nov 24, 2013 at 2:18 AM, Christian Gollwitzer wrote: >> Am 24.11.13 04:41, schrieb Chris Angelico: >> >>> As part of a post on python-ideas, I wanted to knock together a quick >>> little script that "imports" a file based on its name, in

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Sun, Nov 24, 2013 at 2:18 AM, Christian Gollwitzer wrote: > Am 24.11.13 04:41, schrieb Chris Angelico: > >> As part of a post on python-ideas, I wanted to knock together a quick >> little script that "imports" a file based on its name, in the same way >> that the Python interpreter will happily

Re: Importing by file name

2013-11-24 Thread Christian Gollwitzer
Am 24.11.13 04:41, schrieb Chris Angelico: As part of a post on python-ideas, I wanted to knock together a quick little script that "imports" a file based on its name, in the same way that the Python interpreter will happily take an absolute pathname for the main script. Is it imp.load_source()

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Sun, Nov 24, 2013 at 7:00 PM, Ian Kelly wrote: > The importer mechanism as far as I know only accepts module names, not > filesystem paths; I believe this is by design. You could imitate it by > doing something like this: > > import imp > import sys > > mod = imp.new_module('spam') > exec(open

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Nov 23, 2013 9:42 PM, "Chris Angelico" wrote: > As part of a post on python-ideas, I wanted to knock together a quick > little script that "imports" a file based on its name, in the same way > that the Python interpreter will happily take an absolute pathname for > the main script. I'm sure th

Re: Importing by file name

2013-11-23 Thread Devin Jeanpierre
On Sat, Nov 23, 2013 at 7:41 PM, Chris Angelico wrote: > As part of a post on python-ideas, I wanted to knock together a quick > little script that "imports" a file based on its name, in the same way > that the Python interpreter will happily take an absolute pathname for > the main script. I'm su

Re: Importing Definitions

2013-09-06 Thread Oscar Benjamin
On 5 September 2013 19:06, Skip Montanaro wrote: >>> You can! Any name will work, functions aren't special. >>> >>> from module1 import method1, A, B, C, D, E >> >> Better practice is to use: >> >> import module1 >> print module1.A >> print module2.B >> >> and so forth since that makes it far more

Re: Importing Definitions

2013-09-06 Thread Azureaus
Thanks for the advice, much appreciated - I didn't realise you could also import definitions. I do always read the documentation before posting but sometimes I don't know how it's necessarily applicable to my own case sometimes - hence the post. I'll avoid using '*' at all costs, I've had the pl

Re: Importing Definitions

2013-09-05 Thread Skip Montanaro
>> You can! Any name will work, functions aren't special. >> >> from module1 import method1, A, B, C, D, E > > Better practice is to use: > > import module1 > print module1.A > print module2.B > > and so forth since that makes it far more clear what you are doing and > where they come from. But it'

Re: Importing Definitions

2013-09-05 Thread Steven D'Aprano
On Thu, 05 Sep 2013 22:50:35 +1000, Chris Angelico wrote: > On Thu, Sep 5, 2013 at 10:39 PM, Azureaus > wrote: >> Now I know if there was a method I wanted to reference I could do >> something like this in module2. from module1 import method1 >> >> which would mean from that point on I could jus

Re: Importing Definitions

2013-09-05 Thread Ethan Furman
On 09/05/2013 05:39 AM, Azureaus wrote: This will throw an error saying "global name 'A' is not defined." In Python, "global" really means "module-level". Now I know if there was a method I wanted to reference I could do something like this in module2. from module1 import method1 which wo

Re: Importing Definitions

2013-09-05 Thread Peter Otten
Azureaus wrote: > This will throw an error saying "global name 'A' is not defined." > > Now I know if there was a method I wanted to reference I could do > something like this in module2. > from module1 import method1 What a crazy idea! How could anyone ever think of that! > which would mean

Re: Importing Definitions

2013-09-05 Thread Chris Angelico
On Thu, Sep 5, 2013 at 10:39 PM, Azureaus wrote: > Lets say I have some definitions in a module1.py e.g. > > import sys > A,B,C,D,E = range(5) > def method1(): > more code > end > > Then a second module module2.py where I wish to use these definitions > import module1.py > print A > > This will th

Re: Importing variables non-deterministic?

2013-08-20 Thread wxjmfauth
Le mardi 20 août 2013 09:55:44 UTC+2, Antoon Pardon a écrit : > Op 20-08-13 09:31, wxjmfa...@gmail.com schreef: > > > Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : > > >> > > >>> > > >> > > > > > >> > > >> > > >> > > >>> If you consider the implementation of sin and cos fu

Re: Importing variables non-deterministic?

2013-08-20 Thread Antoon Pardon
Op 20-08-13 09:31, wxjmfa...@gmail.com schreef: > Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : >> >>> >> > >> >> >> >>> If you consider the implementation of sin and cos functions, they usually >> >>> reduce the argument modulo π to something in the first quadrant, and then >> >

Re: Importing variables non-deterministic?

2013-08-20 Thread wxjmfauth
Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : > > > > > > > > > If you consider the implementation of sin and cos functions, they usually > > > reduce the argument modulo π to something in the first quadrant, and then > > > use symmetry to adjust the value. So changing th

  1   2   3   4   5   6   >