John wrote:
> Does anyone know why the script below works fine (in regards to the
> 'source function') but when I try to uncomment the line from mymod
> import source and use it that way without defining the function in the
> script, I get an error that N_id does not exist. It must have somethin
Does anyone know why the script below works fine (in regards to the 'source
function') but when I try to uncomment the line from mymod import source and
use it that way without defining the function in the script, I get an error
that N_id does not exist. It must have something to do with namespace
"John" <[EMAIL PROTECTED]> wrote
> But won't if fail since the variabls in the file are not quoted?
No the quoting is only necessary if you use eval/exec.
The quotes prevent the interpreter from treating them as
variable names.
If you read the values from the file they are already strings,
But won't if fail since the variabls in the file are not quoted?
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"John" <[EMAIL PROTECTED]> wrote
>I have a file sitelocations:
>
> STN_id[1]=AAA
> STNlat[1]=58.80
> STNlon[1]=17.40
> STNelv[1]=20
> STN_id[2]=BBB
> STNlat[2]=42.45
> STNlon[2]=25.58
> STNelv[2]=2925
>
> which in shell scripts I can simple 'source'.
> In Python I have to:
>
Thanks,
it's strange, it works within a script defined at the top, but if I try to
import it from a module it fails:
NameError: name 'files' is not defined
On 10/27/07, Aditya Lal <[EMAIL PROTECTED]> wrote:
>
>
>
> On 10/27/07, John <[EMAIL PROTECTED]> wrote:
> >
> > Note, i need the ns+1 beca
On 10/27/07, John <[EMAIL PROTECTED]> wrote:
>
> Note, i need the ns+1 because the 'source files are not zero indexed.
>
> On 10/27/07, John <[EMAIL PROTECTED] > wrote:
> >
> > Here's where I am:
> >
> >
> > def source(filename, vList):
> > """ takes a file object and a list of variables as input
Note, i need the ns+1 because the 'source files are not zero indexed.
On 10/27/07, John <[EMAIL PROTECTED]> wrote:
>
> Here's where I am:
>
>
> def source(filename, vList):
> """ takes a file object and a list of variables as input """
> import re
> # Read the file
> fid=open(filename,'r')
>
Here's where I am:
def source(filename, vList):
""" takes a file object and a list of variables as input """
import re
# Read the file
fid=open(filename,'r')
lines = fid.readlines()
fid.close()
#how many variables
ns=len(lines)/len(vList)
#predefine the varibles
for v in vList:
exec(
On 10/27/07, John <[EMAIL PROTECTED]> wrote:
>
> The problem is the infies are also being used in a shell scripted
> environment, they are frequently updated and cannot be changed.
>
> So ideadly I could just define a function which sourced the file, assuming
> the variable names passed in the *arg
The problem is the infies are also being used in a shell scripted
environment, they are frequently updated and cannot be changed.
So ideadly I could just define a function which sourced the file, assuming
the variable names passed in the *args list. So, yes, I know the names, they
just haven't bee
On 10/27/07, John <[EMAIL PROTECTED]> wrote:
>
> Ok, so trying to convert it to a function:
>
> def source(ifile, *args):
> """ takes a file object and a list of variables as input.
> assumes, source file has variables in format:
> VAR[i]=variable """
>
> imp
Ok, so trying to convert it to a function:
def source(ifile, *args):
""" takes a file object and a list of variables as input.
assumes, source file has variables in format:
VAR[i]=variable """
import re
# Read the file
lines = fd.readlines()
Thanks! This is helpful.. I like the RE approach as it's conceivable to
write a function...
On 10/27/07, Aditya Lal <[EMAIL PROTECTED]> wrote:
>
> You can source the file in python provided that you make it python
> friendly:-
>
> STN_id[1]='AAA' instead of STN_id[1]=AAA
> ...
>
>
> ---
>
You can source the file in python provided that you make it python
friendly:-
STN_id[1]='AAA' instead of STN_id[1]=AAA
...
---
import re
# Read the file
fd = open('sitelocations')
lines = fd.readlines()
fd.close()
# Make it python friendly: put all values in 'single quotes'
cmd = '\n'.joi
John wrote:
> I have a file sitelocations:
>
> STN_id[1]=AAA
> STNlat[1]=58.80
> STNlon[1]=17.40
> STNelv[1]=20
> STN_id[2]=BBB
> STNlat[2]=42.45
> STNlon[2]=25.58
> STNelv[2]=2925
>
> which in shell scripts I can simple 'source'. In Python I have to:
> sitesFile=file('sitelocat
I have a file sitelocations:
STN_id[1]=AAA
STNlat[1]=58.80
STNlon[1]=17.40
STNelv[1]=20
STN_id[2]=BBB
STNlat[2]=42.45
STNlon[2]=25.58
STNelv[2]=2925
which in shell scripts I can simple 'source'. In Python I have to:
sitesFile=file('sitelocations','r')
sites=sitesFile.readlines()
i
17 matches
Mail list logo