argv

Taking txt files with unknown names as parameters (Python)

Taking txt files with unknown names as parameters (Python) Question: I am trying to write a program in Pycharm that can take the name of 2 txt files as an input and then use that input to execute some set of instructions. I understand I can put the name of a txt file in the …

Total answers: 1

How to pass a numbers list to function using command line sys.argv Python3

How to pass a numbers list to function using command line sys.argv Python3 Question: I want to use sys.argv[] to get a list of 5 numbers from the command line to a function (def calc_avg), so they can be averaged. But I keep getting – TypeError: int() argument must be a string, a bytes-like object …

Total answers: 1

How to use python argparse with args other than sys.argv?

How to use python argparse with args other than sys.argv? Question: Is there a way to use argparse with any list of strings, instead of only with sys.argv? Here’s my problem: I have a program which looks something like this: # This file is program1.py import argparse def main(argv): parser = argparse.ArgumentParser() # Do some …

Total answers: 3

How do I take unlimited sys.argv[] arguments?

How do I take unlimited sys.argv[] arguments? Question: To elaborate, I am interested in learning how to code out in python a sys.argv[] function that allows the user to supply as many arguments as the user wants. I am unsure on if there is a better way to do this or if it can be …

Total answers: 1

How to use raw_input with argv?

How to use raw_input with argv? Question: I’m doing ex13 from Learn Python The Hard Way I’m trying to pass: python ex13.py raw_input() raw_input() raw_input() my code is below: from sys import argv script, first, second, third = argv print “The script is called:”, script print “Your first variable is:”, first print “Your second variable …

Total answers: 9

Numbers passed as command line arguments in python not interpreted as integers

Numbers passed as command line arguments in python not interpreted as integers Question: I am familiar with C, and have started experimenting in python. My question is regarding the sys.argv command. I’ve read it is used for a command line interpreter, but when trying to execute a simple program I don’t get the results I …

Total answers: 6

Problem with sys.argv[1] when unittest module is in a script

Problem with sys.argv[1] when unittest module is in a script Question: I have a script that does various things and access parameters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value …

Total answers: 4

An integer is required? open()

An integer is required? open() Question: I have a very simple python script that should scan a text file, which contains lines formatted as id=’value‘ and put them into a dict. the python module is called chval.py and the input file is in.txt. here’s the code: import os,sys from os import * from sys import …

Total answers: 7

How to parse strings to look like sys.argv

How to parse strings to look like sys.argv Question: I would like to parse a string like this: -o 1 –long “Some long string” into this: [“-o”, “1”, “–long”, ‘Some long string’] or similar. This is different than either getopt, or optparse, which start with sys.argv parsed input (like the output I have above). Is …

Total answers: 2