Converting csh script to Pyhton


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting csh script to Pyhton
# 1  
Old 11-06-2010
Converting csh script to Pyhton

I am trying to call this python script

tdarwin.py -nxz=23x35

and should take the -nxz and take the values 23 and 35 to two variables. But am getting the error "option -n not recognized"

Code:
    long_opts= [
    "tpath=",
    "fbase=",
    "fdata=",
    "fstmod=",
    "frestore=",
    "ftag=",
    "tee=",
    "nxz=",
    "npop=",
    "varp=",
    "sigma=",
    "maxiter=",
    "dtau=",
    "mdacc=",
    "mindist=",
    "maxitertp=",
    "tpf=",
    "vrb=",
    "usage",
    "help"]
    try:

        optlist, args = getopt.getopt(sys.argv[1:], "", long_opts)

    except getopt.GetoptError, err:
        print str(err) # will print something like "option -a not recognized"
        print_usage()
        sys.exit(2)

    for opt, val in optlist:

        if opt == "--nxz":
            nxp = val.split('x')[0];
            nzp = val.split('x')[1];
            print " -nxz = nxz"
            print " -nxz = ",val
            print ""

        elif opt == "--npop":
            npop = val
            print " -npop = npop"
            print " -npop = ",val
            print ""

        elif opt == "--varp":
             varpint = val.split('.')[0]
             varpfrc = val.split('.')[1]
             print " -varp = varp"
             print " -varp = ",val
             print ""

        elif opt == "--sigma":
            sigma = val
            print " -sigma = sigma"
            print " -sigma = ",val
            print ""

        elif opt == "--help":

            print_usage()
            sys.exit()

        else:
            print ""
            print "ERROR: Unrecognised argument,",opt
            print ""
            sys.exit(-1)


Last edited by kristinu; 11-06-2010 at 06:58 PM..
# 2  
Old 11-06-2010
Hi.

I know nothing about Python, but your code says:
Code:
if opt == "--nxz":

yet you called it with a single dash:
Code:
tdarwin.py -nxz=23x35

Best wishes ... cheers, drl
# 3  
Old 11-06-2010
Yeah, it seems it's standard in Python to use -- for variables. Thanks. Works using --. I'm trying to learn it myself, just started.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting awk script from bash to csh

I have the following script set up and working properly in bash. It basically copies a set of lines which match "AS1100002" from one file and replaces the same lines in another file. awk -vN=AS1100002* 'NR==FNR { if($1 ~ N)K=$0; next } { if($1 in K) $0=K; print }' $datadir/file1... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

2. Shell Programming and Scripting

how to get the value of a registry using csh script.

hi, how to get the value of a registry using csh script. thanks. (1 Reply)
Discussion started by: Rashid Khan
1 Replies

3. Shell Programming and Scripting

IF is not working in csh script

cat tmp0.txt 700000 #!/bin/csh -fx set id=`cat tmp0.txt` echo $id if ("$id" == "700000") then echo "Good Morning" endif if ("$id" == "700002") then echo "Good evening" endif My output from terminal set id=`cat tmp0.txt` cat tmp0.txt echo 700000 700000 ==... (9 Replies)
Discussion started by: vivien_chu
9 Replies

4. UNIX for Dummies Questions & Answers

Csh script

Hey all, I've only just started using UNIX coding on my Masters project, so am still learning!! The script I've been writing is literally just for me to get used to writing it and seeing what I can do with some data I've been given. I'm trying to write a script, where the penultimate line... (2 Replies)
Discussion started by: southernlight
2 Replies

5. Shell Programming and Scripting

csh script help

Hey I am brand new to this forum and scripting. I have several documents (1000+) all formated exactly the same. Each document contains 97 lines. I want to pull 3 lines from the documents to populate a file. These 3 lines are line number 9, 24, and 58. Ok my questions: Instead of using... (3 Replies)
Discussion started by: david6789
3 Replies

6. Shell Programming and Scripting

how to source csh script in tcl script

i have atcl script and i want to source a csh script to reflect changes done by script ........ Please help....... (0 Replies)
Discussion started by: paragarora47
0 Replies

7. Shell Programming and Scripting

Help with csh script

Ok I asked something similar earlier with no response, so maybe I didn't word it correctly. I'm new at this, so thank you for your help. Here's what I have right now. ---------------------------- > cat MySourceFile #!/bin/csh echo "Please Enter Value For My_Env_Var:" set answer = $< ... (1 Reply)
Discussion started by: MMorrison
1 Replies

8. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

9. Shell Programming and Scripting

Problem with csh script

Hi All, I have the following script. #!/bin/csh # # createDATfile.sh # cd /export/home/fastserv/bin source /export/home/fastserv/bin/dbenv.sh echo `date` >> /export/home/fastserv/bin/log.txt echo "%INF% Starting send of current FASTSERVICE batch" >>... (4 Replies)
Discussion started by: rahulrathod
4 Replies

10. Shell Programming and Scripting

Converting bash script to csh

Hi, I'm a beginner in scripting and I recently wrote a bash script that would've worked fine until I realized it needed to be written in csh. Could someone please show me how to correctly change the syntax from bash to csh in this script? Any help will be greatly appreciated. I can provide more... (4 Replies)
Discussion started by: Kweekwom
4 Replies
Login or Register to Ask a Question