LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-06-2012, 03:57 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
python simple syntax


Hi, I am trying to pass variable into a python script:
Code:
#!/usr/bin/env python
import sys
import transmissionrpc

num=sys.argv[1]
print num
tc = transmissionrpc.Client(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
t=tc.info(num)[num]
print t.name
print t.status
print t.progress
print t.comment
print t.date_added
print t.date_active
print t.date_started
print t.date_done
But this returns the following error:
Code:
Traceback (most recent call last):
  File "/mnt/sda1/script/test.sh", line 9, in <module>
    t=tc.info(num)[num]
KeyError: '1'
Thanks,
Ted
 
Old 04-06-2012, 06:56 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
looks like tc.info() isn't returning an array, so you can't get element one of that array. as it's not an array. try printing out tc.info(num) maybe.
 
Old 04-06-2012, 09:11 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,495

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
I think you'll want
Code:
num = int(sys.argv[1])
otherwise num is actually a string.
 
1 members found this post helpful.
Old 04-06-2012, 10:01 PM   #4
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Thanks, that worked
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Python Installed; bash command: python base.py. gets syntax error in base.py cre84j Linux - Software 4 01-23-2011 04:46 PM
[SOLVED] How to do syntax highlighting in a python-qt application ? Snouffelaire Linux - Software 4 11-13-2009 03:19 AM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
Python MySQLdb syntax issues... elvenson Programming 4 12-18-2007 12:36 PM
python syntax error, what am I doing wrong? Tortanick Programming 1 04-03-2007 10:37 AM


All times are GMT -5. The time now is 10:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration