Escape a console string containing a path with “r” (python) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Print “n” or newline characters as part of the output on terminalCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?How do I parse a string to a float or int in Python?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?How do I lowercase a string in Python?
How come Sam didn't become Lord of Horn Hill?
If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?
Using audio cues to encourage good posture
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
How do I make this wiring inside cabinet safer? (Pic)
Trademark violation for app?
An adverb for when you're not exaggerating
Is "Reachable Object" really an NP-complete problem?
Is there a kind of relay only consumes power when switching?
Do square wave exist?
Wu formula for manifolds with boundary
What does "lightly crushed" mean for cardamon pods?
What do you call the main part of a joke?
Can a party unilaterally change candidates in preparation for a General election?
Can anything be seen from the center of the Boötes void? How dark would it be?
Circuit to "zoom in" on mV fluctuations of a DC signal?
Where are Serre’s lectures at Collège de France to be found?
Compare a given version number in the form major.minor.build.patch and see if one is less than the other
Crossing US/Canada Border for less than 24 hours
Can a new player join a group only when a new campaign starts?
Dating a Former Employee
Should I use a zero-interest credit card for a large one-time purchase?
Is the Standard Deduction better than Itemized when both are the same amount?
How can I use the Python library networkx from Mathematica?
Escape a console string containing a path with “r” (python)
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Print “n” or newline characters as part of the output on terminalCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?How do I parse a string to a float or int in Python?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?How do I lowercase a string in Python?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to send the following commands to a busybox device via a serial port:
SBC1000 > setenv serverip '192.168.128.100'
SBC1000 > setenv fsfile '1kroot.jffs2-128k'
SBC1000 > saveenv
I can escape the single quotes of the first line without a problem using a backslash:
cmd = 'setenv serverip '192.168.128.100''
I've tried various combinations of backslashes for the second line, but couldn't get the 1kroot part to escape properly. I believe it is being interpreted as a return. I tried double and triple escape with no success.
I finally stumbled upon using
cmd = 'setenv fsfile '1k\u0072oot.jffs2-128k''
to include the r ( not a return ) for my string.
Is there a more readable way to include this r ( not a return ) pattern in my string?
python escaping python-unicode
add a comment |
I need to send the following commands to a busybox device via a serial port:
SBC1000 > setenv serverip '192.168.128.100'
SBC1000 > setenv fsfile '1kroot.jffs2-128k'
SBC1000 > saveenv
I can escape the single quotes of the first line without a problem using a backslash:
cmd = 'setenv serverip '192.168.128.100''
I've tried various combinations of backslashes for the second line, but couldn't get the 1kroot part to escape properly. I believe it is being interpreted as a return. I tried double and triple escape with no success.
I finally stumbled upon using
cmd = 'setenv fsfile '1k\u0072oot.jffs2-128k''
to include the r ( not a return ) for my string.
Is there a more readable way to include this r ( not a return ) pattern in my string?
python escaping python-unicode
Did you trycmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string:cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Use a raw stringcmd = r"setenv fsfile '1kroot.jffs2-128k'"
?
– snakecharmerb
Mar 8 at 19:02
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06
add a comment |
I need to send the following commands to a busybox device via a serial port:
SBC1000 > setenv serverip '192.168.128.100'
SBC1000 > setenv fsfile '1kroot.jffs2-128k'
SBC1000 > saveenv
I can escape the single quotes of the first line without a problem using a backslash:
cmd = 'setenv serverip '192.168.128.100''
I've tried various combinations of backslashes for the second line, but couldn't get the 1kroot part to escape properly. I believe it is being interpreted as a return. I tried double and triple escape with no success.
I finally stumbled upon using
cmd = 'setenv fsfile '1k\u0072oot.jffs2-128k''
to include the r ( not a return ) for my string.
Is there a more readable way to include this r ( not a return ) pattern in my string?
python escaping python-unicode
I need to send the following commands to a busybox device via a serial port:
SBC1000 > setenv serverip '192.168.128.100'
SBC1000 > setenv fsfile '1kroot.jffs2-128k'
SBC1000 > saveenv
I can escape the single quotes of the first line without a problem using a backslash:
cmd = 'setenv serverip '192.168.128.100''
I've tried various combinations of backslashes for the second line, but couldn't get the 1kroot part to escape properly. I believe it is being interpreted as a return. I tried double and triple escape with no success.
I finally stumbled upon using
cmd = 'setenv fsfile '1k\u0072oot.jffs2-128k''
to include the r ( not a return ) for my string.
Is there a more readable way to include this r ( not a return ) pattern in my string?
python escaping python-unicode
python escaping python-unicode
asked Mar 8 at 18:57
Phil BrooksPhil Brooks
64948
64948
Did you trycmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string:cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Use a raw stringcmd = r"setenv fsfile '1kroot.jffs2-128k'"
?
– snakecharmerb
Mar 8 at 19:02
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06
add a comment |
Did you trycmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string:cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Use a raw stringcmd = r"setenv fsfile '1kroot.jffs2-128k'"
?
– snakecharmerb
Mar 8 at 19:02
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06
Did you try
cmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string: cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Did you try
cmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string: cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Use a raw string
cmd = r"setenv fsfile '1kroot.jffs2-128k'"
?– snakecharmerb
Mar 8 at 19:02
Use a raw string
cmd = r"setenv fsfile '1kroot.jffs2-128k'"
?– snakecharmerb
Mar 8 at 19:02
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06
add a comment |
1 Answer
1
active
oldest
votes
The solution was to use double-quotes " " as suggested by John Szakmeister.
I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.
My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069368%2fescape-a-console-string-containing-a-path-with-r-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The solution was to use double-quotes " " as suggested by John Szakmeister.
I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.
My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.
add a comment |
The solution was to use double-quotes " " as suggested by John Szakmeister.
I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.
My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.
add a comment |
The solution was to use double-quotes " " as suggested by John Szakmeister.
I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.
My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.
The solution was to use double-quotes " " as suggested by John Szakmeister.
I discovered that the command string was being passed to a function inside a private class based on pexpect-serial.
My guess is that my string was being evaluated by pexpect in a greedy way. By using a distinct delimiter, the problem was overcome.
answered Mar 19 at 15:46
Phil BrooksPhil Brooks
64948
64948
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069368%2fescape-a-console-string-containing-a-path-with-r-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you try
cmd = "setenv fsfile '1k\root.jffs2-128k'"
? Or use a raw string:cmd = r"setenv fsfile '1kroot.jffs2-128k'"
– John Szakmeister
Mar 8 at 19:02
Use a raw string
cmd = r"setenv fsfile '1kroot.jffs2-128k'"
?– snakecharmerb
Mar 8 at 19:02
I found this thread here, might solve it. Can't try it myself rn.
– Aeossa
Mar 8 at 19:06