1

https://docs.python.org/2/tutorial/introduction.html#unicode-strings

I'm currently trying to figure out how to dynamically create u-strings (which are in the form of u'helloWorld' for example). I'd like to create a u-string with string concatenation or string injection if it were possible, to use a variable to dynamically create a new u-string such as u'{variableName}'. Is there a way to accomplish this?

The usage of the Python 2 u-strings are for usage of the gcloud functions, where I'm trying to dynamically add documents. The documentation makes use of u-strings and can be found at:

https://firebase.google.com/docs/firestore/manage-data/add-data

9
  • 3
    Strings vs. unicode strings only makes sense in Python 2, and Python 2 seldom makes sense in 2021. What are you trying to accomplish? (In fairness, Apple has muddied the waters by making Python 2 their default for way too long). Commented May 20, 2021 at 19:27
  • Are you actually using Python 2? In Python 3, all strings are Unicode. They're managed just like regular strings. Commented May 20, 2021 at 19:27
  • 1
    Why are you doing a tutorial for Python 2? Commented May 20, 2021 at 19:27
  • What have you tried that isn't working? mys = u"one" + u"two" should work fine in Python 2. Commented May 20, 2021 at 19:28
  • 1
    Python 2 reached its end of life on January 1, 2020. And all strings are u-strings by default in Python 3 if I'm not wrong. Commented May 20, 2021 at 19:29

1 Answer 1

1

u-strings don't exist anymore in Python 3. They are the same as normal strings. So just use normal strings.

# Python 3
>>> u'Hello'
'Hello'

Do not use Python 2 as it is no longer supported. If you insist on using Python 2, try:

# Python 2
>>> unicode('Hello')
u'Hello'
Sign up to request clarification or add additional context in comments.

2 Comments

It's for use in gcloud functions (firebase.google.com/docs/firestore/manage-data/add-data), I don't have another way around it.
@cloudxleaf OK, it is just a weird way to write normal strings then. Just use a normal string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.