Forwarding to list since I seem to have messed up the address last time... -------- Forwarded Message -------- Subject: Re: [Tutor] Argparse Error Date: Sun, 12 Aug 2018 23:44:04 +0100 From: Alan Gauld <alan.ga...@yahoo.co.uk> Reply-To: tutor <tutor@python.org> To: Nathan Johnson <nathanj9...@gmail.com>
On 12/08/18 19:58, Nathan Johnson wrote: > Here is the full script that was provided, but I don't know what else > I'm supposed to do with it except save it in the folder on my D: > drive, and run in in the cmd prompt like you said. > OK, It seems as if there are some other arguments that you need to provide. The one causing the issue here is fileout - ie the output filename. Now, its not clear what else needs to be specified, you probably should ask the author. We are not really best qualified to decipher another coders code! But it looks like values for interval, shift and skip are required too - although I've no idea what they mean! What the code does tell us are the options you need to use, so the command should look like: python D:\Python\bytsh.py -o output.mp4 -i ??? -s ??? -k ??? D:\Video\test.mp4 Where you will need to figure out what kind of values to use for the ??? parts. > > import argparse > > > parser = argparse.ArgumentParser(description="Shift bytes in a file") > > parser.add_argument("file", help="input file") > > parser.add_argument("-o", "--output", help="output file") > > parser.add_argument("-i", "--interval", help="byte interval", > default=1000) > > parser.add_argument("-s", "--shift", help="size of shift", default=4) > > parser.add_argument("-k", "--skip", help="size of initial skip > offset", default=128) > > args = parser.parse_args() > > > filein = args.file > > fileout = args.output > > interval = int(args.interval) > > shift = int(args.shift) > > skip = int(args.skip) > > > f = open(filein, "rb") > > out = open(fileout, "w+b") > > > out.write( f.read1(skip) ) > > > while True: > > byte = f.read1(1) > > if byte == b'': > > break > > I suspect the three lines above should be indented under the whilew like this: while True: byte = f.read1(1) if byte == "b": break But I don't know if any of the lines below should be indented too... The next 3 could be. And maybe they are in the original and its the mail system thats destroyed them? You need to post in plain text for us to accurately see the original indentation levels (which are critically important in Python) > lbfr = f.read(shift) > > rbfr = f.read(interval-shift) > > out.write(lbfr + byte + rbfr) > > > f.close() > > out.close() > > > This is what the cmd prompt says when I type in the new command > > C:\Users\natha> python D:\Python\bytsh.py D:\Video\test.mp4 > Traceback (most recent call last): > File "D:\Python\bytsh.py", line 18, in <module> > out = open(fileout, "w+b") > TypeError: expected str, bytes or os.PathLike object, not NoneType > HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor