473,241 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

TRying to import files from my folder not pythons lib folder

Hi,

I'm trying to create my own lib of functions, but it seems like I can
only import them if they are in pythons lib folder.

Example
I have a folder called
K:\mypython

Now in the interactive python shell I type
Import k:\mypython\listall
And get a error on :

If I store listall.py in pythons lib folder and type
Limport listall

It works fins.

Can I create my own library of functions and store them in a separate
dir????

Also I try to creat a folder in pythomns lib folder and that did not
work

Help
-Ted

Sep 21 '07 #1
6 1983
On Sep 21, 12:32 pm, "tedpot...@gmail.com" <tedpot...@gmail.com>
wrote:
Hi,

I'm trying to create my own lib of functions, but it seems like I can
only import them if they are in pythons lib folder.

Example
I have a folder called
K:\mypython

Now in the interactive python shell I type
Import k:\mypython\listall
And get a error on :

If I store listall.py in pythons lib folder and type
Limport listall

It works fins.

Can I create my own library of functions and store them in a separate
dir????

Also I try to creat a folder in pythomns lib folder and that did not
work

Help
-Ted
One workaround is to do to this:

<code>

import sys
sys.path.append(r'K:\mypython')
import listall

</code>

You can also add your path to the .pth file, but I've never done that,
so I can't tell you how.

Hope that helps!

Mike

Sep 21 '07 #2
ky******@gmail.com wrote:
On Sep 21, 12:32 pm, "tedpot...@gmail.com" <tedpot...@gmail.com>
wrote:
>Hi,

I'm trying to create my own lib of functions, but it seems like I can
only import them if they are in pythons lib folder.

Example
I have a folder called
K:\mypython

Now in the interactive python shell I type
Import k:\mypython\listall
And get a error on :

If I store listall.py in pythons lib folder and type
Limport listall

It works fins.

Can I create my own library of functions and store them in a separate
dir????

Also I try to creat a folder in pythomns lib folder and that did not
work

Help
-Ted

One workaround is to do to this:

<code>

import sys
sys.path.append(r'K:\mypython')
import listall

</code>

You can also add your path to the .pth file, but I've never done that,
so I can't tell you how.

Hope that helps!

Mike
The easiest way, particularly for testing, is to set the PYTHONPATH
variable. It should be a colon-separated list of directories on Unices,
and a semi-colon separated list on Windows. Those directories will be
added to sys.path.

See http://docs.python.org/tut/node8.html for yet more.

regards
Steve

--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 21 '07 #3

Steve Holden wrote:
ky******@gmail.com wrote:
On Sep 21, 12:32 pm, "tedpot...@gmail.com" <tedpot...@gmail.com>
wrote:
Hi,

I'm trying to create my own lib of functions, but it seems like I can
only import them if they are in pythons lib folder.

Example
I have a folder called
K:\mypython

Now in the interactive python shell I type
Import k:\mypython\listall
And get a error on :

If I store listall.py in pythons lib folder and type
Limport listall

It works fins.

Can I create my own library of functions and store them in a separate
dir????

Also I try to creat a folder in pythomns lib folder and that did not
work

Help
-Ted
One workaround is to do to this:

<code>

import sys
sys.path.append(r'K:\mypython')
import listall

</code>

You can also add your path to the .pth file, but I've never done that,
so I can't tell you how.

Hope that helps!

Mike
The easiest way, particularly for testing, is to set the PYTHONPATH
variable. It should be a colon-separated list of directories on Unices,
and a semi-colon separated list on Windows. Those directories will be
added to sys.path.

See http://docs.python.org/tut/node8.html for yet more.

regards
Steve

--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
This is exactly what I did, but I have a new problem now:
After seting PYTHONPATH I'm no longer able to start IDLE from the
start menu.
It seems the system cannot find the file.
But if I eliminate PYTHONPATH, everything works as it used to.

I set PYTHONPATH because I wanted to import any existing file in my
desktop without having to use sys.path.append...
It works when using the command line but strangely, something get
messed up with IDLE.
Any hint?

Luis

Sep 24 '07 #4
En Sun, 23 Sep 2007 22:01:39 -0300, Luis M. González <lu*****@gmail.com>
escribi�:
This is exactly what I did, but I have a new problem now:
After seting PYTHONPATH I'm no longer able to start IDLE from the
start menu.
It seems the system cannot find the file.
But if I eliminate PYTHONPATH, everything works as it used to.

I set PYTHONPATH because I wanted to import any existing file in my
desktop without having to use sys.path.append...
It works when using the command line but strangely, something get
messed up with IDLE.
Any hint?
Perhaps a python module in your desktop has a name conflicting with a
standard module?

- On the Start menu, navigate to the IDLE item, but dont click it.
- RIGHT click on it, and select Properties. Copy the Destination field.
Should be something like "C:\Python25\Lib\idlelib\idle.bat"
- Open a cmd window (console), paste the above text and press Enter.
- Almost certainly you'll get an error; post here the full error and
traceback.

--
Gabriel Genellina

Sep 24 '07 #5
On Sep 24, 5:00 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 23 Sep 2007 22:01:39 -0300, Luis M. Gonzlez <luis...@gmail.com>
escribi?:
This is exactly what I did, but I have a new problem now:
After setingPYTHONPATHI'm no longer able to start IDLE from the
start menu.
It seems the system cannot find the file.
But if I eliminatePYTHONPATH, everything works as it used to.
I setPYTHONPATHbecause I wanted to import any existing file in my
desktop without having to use sys.path.append...
It works when using the command line but strangely, something get
messed up with IDLE.
Any hint?

Perhaps a python module in your desktop has a name conflicting with a
standard module?

- On the Start menu, navigate to the IDLE item, but dont click it.
- RIGHT click on it, and select Properties. Copy the Destination field.
Should be something like "C:\Python25\Lib\idlelib\idle.bat"
- Open a cmd window (console), paste the above text and press Enter.
- Almost certainly you'll get an error; post here the full error and
traceback.

--
Gabriel Genellina
I solved the problem!
You were right. It seems there was a module that was causing problems,
although I don't know which one...
I just moved all the .py files on my desktop to a new folder, and
everything worked just fine.
The list of .py files in my desktop were:

'code.py', 'code2.py', 'code22.py', 'code3.py', 'draft.py',
'flups.py', 'forma.py', 'fx.py', 'nuevo.py', 'nwind', 'ops',
'pages.py', 'qqq.py', 'sample.py', 'ses.py', 'sess.py', 'sess2.py',
'soup.py', 'style.py', 'test_session.py', 'up.py', 'up2.py', 'ww.py',
'xx.pyw', 'xx.rsrc.py', 'xxxx.py'

Any idea of which one was causing trouble?

Gracias, che!
Luis

Sep 25 '07 #6
En Mon, 24 Sep 2007 22:36:38 -0300, Luis M. González <lu*****@gmail.com>
escribi�:
I solved the problem!
You were right. It seems there was a module that was causing problems,
although I don't know which one...
I just moved all the .py files on my desktop to a new folder, and
everything worked just fine.
The list of .py files in my desktop were:

'code.py', 'code2.py', 'code22.py', 'code3.py', 'draft.py',
'flups.py', 'forma.py', 'fx.py', 'nuevo.py', 'nwind', 'ops',
'pages.py', 'qqq.py', 'sample.py', 'ses.py', 'sess.py', 'sess2.py',
'soup.py', 'style.py', 'test_session.py', 'up.py', 'up2.py', 'ww.py',
'xx.pyw', 'xx.rsrc.py', 'xxxx.py'

Any idea of which one was causing trouble?
Possibly code.py, it's a standard module
<http://docs.python.org/lib/module-code.html>
Gracias, che!
De nada loco!

--
Gabriel Genellina

Sep 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Background: I am using a MS Access 2000 front end with SQL Server 8.0 back end. I have the requirement to import all text files (regardless of filename) from a given folder on the network into a...
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
2
by: Josh | last post by:
Currently we open a form and manualy place the pic in each new record. I need someway for to give Access a folder and then have it import each pic it finds in the folder and place the file name in...
2
by: musicloverlch | last post by:
I need to import 60 text files all in one folder. Can I use VBA to cycle through all the files, without having to import them one by one? Does anyone have an example? Thanks in advance. Laura
3
by: gdaniels | last post by:
Hi, I need some help. The routine below runs when a command button is clicked. A prompt appears to enter the directory path to the folder containing delimited text files to be imported into an...
2
by: john | last post by:
I have 400 different Excel-spreadsheetfiles, same structure, all with only one record in it, and all residing in the same folder. Every now and then new Excel files are being added. In my Access...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
2
by: Neil99 | last post by:
hi, I'm using the following function to import files form a specified directory. Admittedly I found it elsewhere and amended it but it does seem to work. Is it possible to take it a step further and...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.