Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,755 members, 7,817,090 topics. Date: Saturday, 04 May 2024 at 04:37 AM

Help Me With This Python Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Me With This Python Code (555 Views)

Can Someone Help With This Python Problems / Help With This Python Programming Assignment Please / Python Masters, Kindly Help Me Rectify This Python Problem. (2) (3) (4)

(1) (Reply) (Go Down)

Help Me With This Python Code by Harkstetunz: 3:26pm On Dec 15, 2020
Hello Programlanders smiley .
I've been learning python for some time using 'Automate the boring stuff' ; I've been scaling through each topic successfully, not until I got to chapter 8 project where the knowledge of command line argument is to be employed in multiclipboard project.
The problem is I don't seems to understand handling command line arguments, as much was not written about it in the book. I've watched some YouTube videos but it's the same old story.
I'm using pycharm text editors.
len(sys.argv)==3 and sys.argv[1].lower()=='save':
for my program to work, the above condition must be true but my len(sys.argv) is always 1 thereby rendering my code useless.
I will really appreciate it if you can help me out or better still recommend any book that comprehensively explains HANDLING COMMAND LINE ARGUMENTS in python



Evilsec
Ibromodzi
Stanliwise
Re: Help Me With This Python Code by ibromodzi: 6:34pm On Dec 15, 2020
Harkstetunz:
Hello Programlanders smiley .
I've been learning python for some time using 'Automate the boring stuff' ; I've been scaling through each topic successfully, not until I got to chapter 8 project where the knowledge of command line argument is to be employed in multiclipboard project.
The problem is I don't seems to understand handling command line arguments, as much was not written about it in the book. I've watched some YouTube videos but it's the same old story.
I'm using pycharm text editors.
len(sys.argv)==3 and sys.argv[1].lower()=='save':
for my program to work, the above condition must be true but my len(sys.argv) is always 1 thereby rendering my code useless.
I will really appreciate it if you can help me out or better still recommend any book that comprehensively explains HANDLING COMMAND LINE ARGUMENTS in python



Evilsec
Ibromodzi
Stanliwise

If
len(sys.argv)
is returning 1, it means you only have one argument in the program which is the filename (or the executable).
sys.argv
returns a list with the first element being the filename followed by other arguments in the program. We'll be able to make significant contributions if you could share the whole code.

Meanwhile, you can go through these links, I hope you find them useful;

https://realpython.com/python-command-line-arguments/


https://www.youtube.com/watch?v=PZN7vVxeh9M&feature=youtu.be

3 Likes

Re: Help Me With This Python Code by valzey(m): 11:44pm On Dec 15, 2020
If you are using pycharm run, you need to set the arguments before running.
However, you can simply

1. Go into the project folder
2. Open cmd or powershell in that folder (shift + right click) and select appropriately.
3. Run py [file].py arg1 arg2
Re: Help Me With This Python Code by Harkstetunz: 8:10am On Dec 16, 2020
Wow! Thanks guys
Re: Help Me With This Python Code by cosmos2000(m): 7:26pm On Dec 25, 2020
Harkstetunz:
Hello Programlanders smiley .
I've been learning python for some time using 'Automate the boring stuff' ; I've been scaling through each topic successfully, not until I got to chapter 8 project where the knowledge of command line argument is to be employed in multiclipboard project.
The problem is I don't seems to understand handling command line arguments, as much was not written about it in the book. I've watched some YouTube videos but it's the same old story.
I'm using pycharm text editors.
len(sys.argv)==3 and sys.argv[1].lower()=='save':
for my program to work, the above condition must be true but my len(sys.argv) is always 1 thereby rendering my code useless.
I will really appreciate it if you can help me out or better still recommend any book that comprehensively explains HANDLING COMMAND LINE ARGUMENTS in python



Evilsec
Ibromodzi
Stanliwise

What version of pycharm are you using...Mine is 2020.3 though I recently downloaded it..but the configuration is something else...can you help me wit it..?

(1) (Reply)

Write A Program That Prints The Integers 1 To 100. For Multiples Of .......... / Getting A Laptop For Programming / Bootstrap Modal Not Working.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.