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


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

File Path/Global name issue

Started byroy.snuffles@gmail.com
First post2014-03-20 12:55 -0700
Last post2014-03-20 21:31 +0000
Articles 6 — 4 participants

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


Contents

  File Path/Global name issue roy.snuffles@gmail.com - 2014-03-20 12:55 -0700
    Re: File Path/Global name issue Skip Montanaro <skip@pobox.com> - 2014-03-20 15:05 -0500
      Re: File Path/Global name issue roy.snuffles@gmail.com - 2014-03-20 13:08 -0700
        Re: File Path/Global name issue Skip Montanaro <skip@pobox.com> - 2014-03-20 15:15 -0500
    Re: File Path/Global name issue Peter Otten <__peter__@web.de> - 2014-03-20 21:26 +0100
    Re: File Path/Global name issue John Gordon <gordon@panix.com> - 2014-03-20 21:31 +0000

#68603 — File Path/Global name issue

Fromroy.snuffles@gmail.com
Date2014-03-20 12:55 -0700
SubjectFile Path/Global name issue
Message-ID<2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com>
I am currently running code for a program called HotNet (https://github.com/raphael-group/hotnet)

In its simpleRun.py file, there is a place to insert a file path to be run. 

parser.add_argument('-mf', '--infmat_file', required=True,
                        help='Path to .mat file containing influence matrix')

My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat

And I have tried to add it in as such: 

Input: 

parser.add_argument('-mf', '--infmat_file', required=True,
                   help= /home/lai/Downloads/influence_matrix_file/hprd_inf_.mat)

Output:   

File "simpleRun.py", line 29
    help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat)
           ^
SyntaxError: invalid syntax

I have also tried to place the path in ' ' but that isn't processed.

I have tried removing the / however that just returns the following error: 

NameError: global name 'home' is not defined


Completely new at this, so thank you for bearing with me and for the help!

[toc] | [next] | [standalone]


#68604

FromSkip Montanaro <skip@pobox.com>
Date2014-03-20 15:05 -0500
Message-ID<mailman.8311.1395345950.18130.python-list@python.org>
In reply to#68603
On Thu, Mar 20, 2014 at 2:55 PM,  <roy.snuffles@gmail.com> wrote:
> File "simpleRun.py", line 29
>     help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat)
>            ^
> SyntaxError: invalid syntax

You need quotes around the filename. It's a string literal.

Skip

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


#68605

Fromroy.snuffles@gmail.com
Date2014-03-20 13:08 -0700
Message-ID<f890ea65-d47d-4b4c-ac12-fd479e42ee60@googlegroups.com>
In reply to#68604
Hi Skip! 
Thank you so much for the response. When I put quotes around the file name I receive this output. 

simpleRun.py: error: argument -mf/--infmat_file is required

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


#68608

FromSkip Montanaro <skip@pobox.com>
Date2014-03-20 15:15 -0500
Message-ID<mailman.8312.1395346545.18130.python-list@python.org>
In reply to#68605
On Thu, Mar 20, 2014 at 3:08 PM,  <roy.snuffles@gmail.com> wrote:
> simpleRun.py: error: argument -mf/--infmat_file is required

I think you are misinterpreting the actual purpose of the
parser_add_argument() call. It's telling you that *on the command
line* you can specify it using either

-mf some-file-name

or

--infmat_file=some-file-name

It also tells you that it is a required argument.

I don't believe you are supposed to have to modify the source to run
the program. I'd set the argument to the "help=..." parameter back to
however it was set when you got it and try either of the above command
line args.

Skip

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


#68610

FromPeter Otten <__peter__@web.de>
Date2014-03-20 21:26 +0100
Message-ID<mailman.8314.1395347194.18130.python-list@python.org>
In reply to#68603
roy.snuffles@gmail.com wrote:

> I am currently running code for a program called HotNet
> (https://github.com/raphael-group/hotnet)
> 
> In its simpleRun.py file, there is a place to insert a file path to be
> run.
> 
> parser.add_argument('-mf', '--infmat_file', required=True,
>                         help='Path to .mat file containing influence
>                         matrix')
> 
> My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat
> 
> And I have tried to add it in as such:
> 
> Input:
> 
> parser.add_argument('-mf', '--infmat_file', required=True,
>                    help=
>                    /home/lai/Downloads/influence_matrix_file/hprd_inf_.mat)
> 
> Output:
> 
> File "simpleRun.py", line 29
>     help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat)
>            ^
> SyntaxError: invalid syntax
> 
> I have also tried to place the path in ' ' but that isn't processed.
> 
> I have tried removing the / however that just returns the following error:
> 
> NameError: global name 'home' is not defined
> 
> 
> Completely new at this, so thank you for bearing with me and for the help!

Reread the documentation, you are misunderstanding it. You don't have to 
modify the simpleRun.py script, you should invoke it from the commandline 
with the file as one of its arguments:

$ python simpleRun.py --infmat_file /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat

As there are more required arguments you will end up with a very long 
command line. But there is an alternative. Create a config file like the 
following

https://github.com/raphael-group/hotnet/blob/master/example/configs/simple.config

where you replace all the file names with those of your actual files and 
then invoke simpleRun.py with

$ python simpleRun.py @roy_snuffles.config

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


#68625

FromJohn Gordon <gordon@panix.com>
Date2014-03-20 21:31 +0000
Message-ID<lgfmn3$rua$1@reader1.panix.com>
In reply to#68603
In <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> roy.snuffles@gmail.com writes:

> I am currently running code for a program called HotNet (https://github.com/raphael-group/hotnet)

> In its simpleRun.py file, there is a place to insert a file path to be run. 

> parser.add_argument('-mf', '--infmat_file', required=True,
>                         help='Path to .mat file containing influence matrix')

> My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat

You're completely misunderstanding the purpose of this line of code.  Its
intent is to allow you to pass the matrix file location to the script by
using the '-mf' or '--infmat_file' arguments, thus not requiring you to
edit the script at all.

The 'help' parameter provides a message explaining the usage of that
particular argument if the simpleRun.py script is executed with the '-help'
option.

For example, if you were unsure how to use the simpleRun.py script, you
might run this command:

    simpleRun.py -help

And you might see output that looks like this:

    Usage: simpleRun.py [options]

    Options:
      -h, --help            show this help message and exit
      -mf, --infmat_file    Path to .mat file containing influence matrix
      -d, --dance           do a little dance
      -l, --love            make a little love

The help message thus informs you that you can provide the location to an
influence matrix file by using the '-mf' or '--infmat_file' arguments.
There are also -d and -l options that do ... something.

-- 
John Gordon         Imagine what it must be like for a real medical doctor to
gordon@panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

[toc] | [prev] | [standalone]


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


csiph-web