Comments (9)
The escape character processing is an inherent feature of Python strings. As is illustrated by this example.
>>> str1="\Tz"
>>> len(str1)
3
>>>
>>> str2="\tz"
>>> len(str2)
2
>>>
>>> str3=r"\tz"
>>> len(str3)
3
>>>
>>> str4="\\tz"
>>> len(str4)
3
And the solution is as described at the end of the initial bug report, namely to use an additional backslash or to use a raw string.
from mdsplus.
Some ideas for consideration . . .
-
Update the documentation on the mdsplus.org web site regarding use of tabs (
\t
) and other special characters in node names / paths passed to the Python API. -
Improve error handling to check for the common special characters in node paths. Because MDSplus uses a backslash to indicate a tag (e.g.,
\TOP
,\NEW_CALC
), when users type those tags in lower case it will be easy to unintentionally create typos (e.g.\top
starts with a tab, and\new_calc
starts with a new-line). -
Not recommended, but it would also be possible for the Python API to detect special characters and convert them back to the two-character mnemonic (e.g, tab is converted to
\t
).
from mdsplus.
For a tool we've been developing internally I just have a line that converts the input string to uppercase (it wants the treenames to be capitalized for some reason, might actually be a related bug come to think of it).
from mdsplus.
The issue is that uppercasing <tab>something
merely makes it <tab>SOMETHING
. As is shown in the following example.
>>> str5 = '\tz'
>>> len(str5)
2
>>> str6 = str5.upper()
>>> str6
'\tZ'
>>> len(str6)
2
To avoid having a <tab>
in a string, one must either . . .
- not type Python strings that contain tabs (i.e., the
\t
sequence), or - have code that scans input strings for special characters and replaces them with two characters (i.e., building up the "raw" string that is equivalent to the user's supposed intent)
from mdsplus.
Ahh, I should have thought of that. Didn't realize the string object got created in memory when it got passed into a function, but it makes sense. My hope was to make it simpler to potentially do preprocessing, but it looks like realistically the outcome here is that while normal MDSplus is not case sensitive, the python API just needs all caps.
from mdsplus.
Hi @ModestMC,
Correct. Users should either use uppercase, raw strings, or double-backslash of special characters (such as \\t
instead of \t
) when entering Python strings that are passed to the Python API for MDSplus.
We could probably add some documentation to the mdsplus.org Wiki if you wish. However, adding a feature to the Python API to scan for special characters would likely be a low priority (e.g., expanding the coverage of the test suite likely is more important).
Should I close this issue?
from mdsplus.
I think the issue is fine to close.
If you can point me at where in the API the preprocessing would need to live, I can see about potentially adding some string preprocessing to fix the input (at least when TDI is attempting to be evaluated). Even then, this issue could be closed as some kind of tech debt/won't fix/etc. Would that be helpful?
from mdsplus.
Hi @ModestMC,
Thanks for your input. I'll look at the code and get back to you. (And I am also inclined to add a few sentences to the mdsplus.org web site explaining the issue with Python strings.)
from mdsplus.
Related Issues (20)
- TCL's `set current` and `show current` commands have problems when using the `$default_tree_path` HOT 6
- Ubuntu 22 build Makefile error HOT 4
- jScope freezes during loading with a "broken pipe" error HOT 20
- closeAllTrees() fails for thin client in python HOT 2
- Make the MDSplus data types or at least the scalar types json serializable
- Add the ability to easily make a static snapshot of a signal HOT 8
- The Motif `traverser` application throws an error when entering an expression into newly created non-text nodes
- Build: add Amazon Linux 2023 as a supported platform
- Build: add Ubuntu 22 on ARM64 as a supported platform
- Build: MATLAB test suite needs correct formatting for the expected output
- Writing to the "current shot" (shot # = 0) via thick-client does not work HOT 3
- MDSplus tries to use OFD locks on systems that do not support it HOT 2
- Unsuccessful read with SS-SUCESS exception using Tree.getNode(...).getData() in Python HOT 31
- MDSplus dispatcher opens lots of files HOT 54
- Activating the `MDSDBG()` debug statements generates compiler errors
- Building on conda forge OSX fails HOT 12
- Mdstcl's "dispatch" feature can trigger segfaults and other errors if flood the "action server" with hundreds of actions HOT 6
- Missing "mdsobjectscppshr-vs.lib" in vs devtools lib32 folder HOT 6
- Some calling routines do not properly handle SsINTERNAL, C_ERROR, and/or FALSE returned by low-level routines HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdsplus.