Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
White Space Help
#1
Hello,

I'm not a programmer and I thought maybe you all could help with this. I am trying to get this script to allow white spaces on the aruguments that get added from the command line when it is run.

import argparse
from twitter import *
parser = argparse.ArgumentParser()
parser.add_argument("description")
parser.add_argument("audio_link")
args = parser.parse_args()

desc = args.description
filename = args.audio_link

#import os
#head, tail = os.path.split(filename)
#print (tail)


twitter =Twitter(auth=OAuth("REMOVED))

with open("Fire.png", "rb") as imagefile:
	imagedata = imagefile.read()
params = {"media[]": imagedata, "status":desc+" page received http://REMOVED/"+filename}

twitter.statuses.update_with_media(**params)
Command to run: python fire.py TEST PAGES INTERNAL 15:28:40 on 12/24/17 TEST_PAGES_INTERNAL_2017_12_24_15_28_33.mp3
It is the part in bold that it is dying on. I got this from someone using it on Linux who doesn't seem to have the same issues as I am running on windows.

If I run python fire.py "TEST PAGES INTERNAL 15:28:40 on 12/24/17" TEST_PAGES_INTERNAL_2017_12_24_15_28_33.mp3 with quotes around the bold part it works but the program that calls this script pukes and dies with the ""'s
Reply
#2
Quote:this script pukes and dies with the ""'s
What does that mean? Post the exact traceback you get.

Quotes around the first argument is required in linux or windows as quotes group together text as one argument. Its all the description argument so it all needs quotes due to the spaces regardless of the system its on. The mp3 filename would require it also if it didnt have underscores but spaces.
Recommended Tutorials:
Reply
#3
I am using this app http://www.twotonedetect.net/

If I put quotes around the wording which fixes my script the app above crashes because it uses the field for filenames etc.. and having quotes around it doesn't work.

[Image: ercSAxl.png]

This is the field from the program. If I leave the quotes it solves one issue but causes more problems.


Is there a way to edit my script to accept TEST PAGES INTERNAL 15:28:40 on 12/24/17 with the spaces?
Reply
#4
Try running it like this:
python fire.py "TEST PAGES INTERNAL 15:28:40 on 12/24/17" "TEST_PAGES_INTERNAL_2017_12_24_15_28_33.mp3"
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#5
(Dec-25-2017, 10:36 AM)Terafy Wrote: Try running it like this:
python fire.py "TEST PAGES INTERNAL 15:28:40 on 12/24/17" "TEST_PAGES_INTERNAL_2017_12_24_15_28_33.mp3"

If I run that manually it 100% works but the twotone program passes on the Arguments it cannot put quotes around it. Thats the problem I am running into. I need to be able to accept the white spaces.
Reply
#6
Sounds like a problem with the program you're using.
Maybe you should ask the author for help?
Reply
#7
(Dec-25-2017, 06:18 PM)stranac Wrote: Sounds like a problem with the program you're using.
Maybe you should ask the author for help?

Not sure asking him to edit this functional program for my script is the best way to solve this. But if there is no way to do it thanks. I'll go look elsewhere.
Reply
#8
Try to change line 4 that way:
parser.add_argument("description", nargs="+")
or
parser.add_argument("description", nargs="*")
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
(Dec-25-2017, 08:53 PM)wavic Wrote: Try to change line 4 that way:
parser.add_argument("description", nargs="+")
or
parser.add_argument("description", nargs="*")

you also need to change the description to
desc = ' '.join(args.description)
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#10
all the operating systems i know break up the arguments from a command and pass just the parts to the program.  so for a program named foo when you type in the command foo abc xyz the program named foo is given the command line arguments as abc and xyz.  if you type it in like   foo    abc      xyz   it still gets the same thing.  to get the exact characters the way they were typed in, the program would have to dig around inside the operating system for it.  while that could be done in Microsoft DOS and early IBM mainframes, newer, more secure operating systems don't let programs have that access in most cases. as described above, when you want spaces to be given to a program, put quotes around each argument and put the spaces you want the program to get inside the quotes like foo "abc  " "  xyz".  you can give it all spaces like foo "      " or even an empty string like foo "".  in most cases you can use either double quotes or single quote (just end each string with the same kind of quote).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  identify not white pixels in bmp flash77 17 2,271 Nov-10-2023, 09:21 PM
Last Post: flash77
  from global space to local space Skaperen 4 2,269 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  White spaces kdiba 1 1,939 Oct-08-2019, 06:52 PM
Last Post: Aurthor_King_of_the_Brittons
  including the white space parts in str.split() Skaperen 6 3,193 Jun-20-2019, 06:03 PM
Last Post: Skaperen
  replace white space with a string, is this pythonic? Skaperen 1 1,979 Jun-18-2019, 11:36 PM
Last Post: metulburr
  Because the emoji appears black and white at the exit ? nerd 3 5,527 Jan-28-2019, 11:34 PM
Last Post: nerd
  Python interface only black and white........ Wilson 3 6,051 Jul-15-2017, 01:20 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020