Questions tagged [rawstring]

A string literal which would be processed without any language-specific interpretation, avoiding the need of escaping characters and thus providing more legible strings.

Raw strings are particularly useful when a common character needs to be escaped, notably in regular expressions (nested as string literals), where backslash \ is widely used, and in DOS/Windows paths, where backslash is used as a path separator.

114 questions
0
votes
2 answers

In Python, how to append a raw string to list?

I have an empty list and I want to append to it a raw string. For example, I have list1 = [] and I want to append the following string '\"quote\"', so I would get ['\"quote\"']. However when I do the following list1 = [] text = '\"quote\"' …
Don
  • 19
  • 1
  • 2
0
votes
1 answer

Raw string to a Powershell script through command line

I have powershell script which takes input from a python GUI. And the script looks like (foo.ps1): #.\foo.ps1 [String]$UserName = $args[0] [String]$Password = $args[1] [String[]] $ComputerName = $args[2] [String[]] $Users = $args[3] Write-Output…
0
votes
3 answers

Python - Getting file directory as user input

Having some trouble getting a list of files from a user defined directory. The following code works fine: inputdirectory = r'C:/test/files' inputfileextensions = 'txt' files = glob.glob(inputdirectory+"*."+inputfileextensions) But I want to allow…
Actuary
  • 129
  • 4
  • 9
0
votes
0 answers

combining raw strings with non raw string

I want to combine a raw string with a non raw one which should be a user input (direct input or config file extracted variable), in order to combine them into a regular expression; import re input = "user_input" regex =…
Ando Jurai
  • 828
  • 1
  • 11
  • 25
0
votes
0 answers

Add raw string macro using target_compile_definitions

I want to add to CMakeLists.txt raw string macro equivalent of: #if defined(Q_OS_WIN) #define COMMPORT_NAME R"(\\.\COM1)" #elif defined(Q_OS_UNIX) #define COMMPORT_NAME "/dev/ttyS0" #else #error "platform not supported" #endif I tried the…
Tomilov Anatoliy
  • 13,614
  • 8
  • 46
  • 134
0
votes
1 answer

python : how to cast or convert string in a variable into raw

x=''' print '\tone \'piece\' of \"metal\" with \\sharp\\ edge ' print '\nthanks' ''' exec(x) I have a string variable (x) and i want to use exec() to print it out correctly. If i have access to the variable i can directly use r' and problem solved,…
andio
  • 903
  • 3
  • 17
  • 30
0
votes
0 answers

Kotlin raw string throws blank error

I'm creating a gradle plugin using kotlin and I am inserting some ascii art. Rather than trying to escape a load of backslashes, I decided to use raw strings but now I'm encountering bizarre nameless errors whenever my line contains 2 vertical…
ddowney
  • 1
  • 1
0
votes
1 answer

How to reflect if a raw or normal string was used?

I have a configuration file where users can provide regular expressions to match against words, e.g. wordlist = ["is", r"\b(and)\b"] The problem is: if a user provides "is", this will also match against "This" -- which is not what I want. The…
duesee
  • 101
  • 1
  • 9
0
votes
2 answers

Raw Strings in Code::Blocks?

I am reading a directory from a file, for example I loaded this "Main\Characters\Player.xxx", so I want to create the folders Main and Characters. I tried using this method (after removing Player.xxx from the string)": string syntax = "md…
thethiny
  • 852
  • 1
  • 7
  • 19
0
votes
0 answers

Regular Expression tested but not working

I have a fairly simple regular expression pattern that I'm trying to match with some raw string literals. I've tested the pattern here (https://regex101.com/r/xT6xU8/2) and it works perfectly, but in my code (snippet below), it doesn't work. import…
Try431
  • 208
  • 3
  • 14
0
votes
1 answer

Scala convert a string to raw

I know raw String can be declared as: val foo: String = """foo""" or val foo: String = raw"foo" However, if I have a string type val, how can I convert it to raw? For example: // val toBeMatched = "line1: foobarfoo\nline2: lol" def…
SexyNerd
  • 934
  • 2
  • 11
  • 18
-1
votes
1 answer

Python Converts the backslash followed by numbers into Unicode

I have a string which is a Windows path returned by another function. The function returns the path with a single backslash within it. Here I can't using raw string conversion to a variable. re.escape(path) does not work either.…
Ritesh
  • 314
  • 6
  • 16
-1
votes
1 answer

Python3: How can I return a raw string containing both " and '. I can't figure it out even with raw string (r'') and escape character (\)

I have recently started python and am having a frustratingly hard time trying to figure out how to print a raw string containing both ' and " characters. Even with various combinations of r'' and \ I cannot get python to return the literal string…
massey95
  • 11
  • 1
-1
votes
2 answers

"[Errno 13] Permission denied" on PIL Image.open if path and filename are not given in a raw string

I am dealing with an issue on the Image.open() function from PIL in Python. I try to open an image from a path / folder saved on a string: path_and_filename = "c:\tmp\test.jpeg" image = Image.open(path_and_filename) Then I get the error: fp =…
-1
votes
1 answer

How to include a variable in 'r' raw string

I've created a new variable for user path, but not sure how to add in to the following. import os, pwd path=os.getcwd() #crif0 = r '/abc/crif/gpio_mem_0_crif.xml' - original crif0 = r (path+ '/crif/gpio_mem_0_crif.xml') - I tried with this but…
Alois
  • 110
  • 2
  • 11