Python Forum
python r string for variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python r string for variable
#4
If it is coming from the command line than it is already a str object and not a str literal. raw does not apply.

I did a little experiment. I wrote a program to spit out the command line argument
import sys
print(f"{sys.argv[1]}, {repr(sys.argv[1])}, {len(sys.argv[1])}"
I ran the program as "python text.py "\\\n". This was the output.
Output:
\\\n, '\\\\\\n', 4
The repr version of the command line argument looks odd, but the length shows this is an artifact of repr trying to show you that the string really contains "\\" and "\n" and not escape<\> and escape<n>.

If backslashes are giving you headaches, use forward slashes. Windows accepts forward slash as a path seperator.
ibreeden likes this post
Reply


Messages In This Thread
python r string for variable - by mg24 - Oct-28-2022, 01:56 AM
RE: python r string for variable - by deanhystad - Oct-28-2022, 02:12 AM
RE: python r string for variable - by mg24 - Oct-28-2022, 02:57 AM
RE: python r string for variable - by deanhystad - Oct-28-2022, 04:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 875 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 2,271 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  USE string data as a variable NAME rokorps 1 1,038 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,519 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 1,931 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,392 Jul-11-2022, 08:52 AM
Last Post: japo85
  Can you print a string variable to printer hammer 2 2,067 Apr-30-2022, 11:48 PM
Last Post: hammer
Question How to convert string to variable? chatguy 5 2,670 Apr-12-2022, 08:31 PM
Last Post: buran
  I want to search a variable for a string D90 lostbit 3 2,718 Mar-31-2021, 07:14 PM
Last Post: lostbit
  Add variable value to string pythonlearner1 5 3,077 May-25-2020, 05:51 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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