Comments (9)
There was one python 3 version which dislike u""
strings.
Can you check if
foo = u"bar"
works for you?
(Just try that quickly, in the interactive shell or something.)
If not, you can either remove all u
s before strings, or upgrade python 3 to some newer version
(which sadly means compiling by yourself... It will take some time, but is worth it in the end - I did that on my Pi too.)
from pytg.
Edit: Just remove the u
in front of the strings. (Python 3+)
"text"
#instead of:
u"text"
Another option, compatible with all Python versions is to import the function pytg use to convert all strings to the right format:
from pytg.encoding import to_unicode as u
This will get any kind of string (byte-encoded or already unicode) correctly to utf-8 unicode (of the according native type str
in python 3, or unicode
in python 2).
Then do
foo = u("bar")
(wrap the string with u()
, which is th imported to_unicode()
)
from pytg.
You are correct. In my Python 3.2.3 interactive terminal, foo = u"bar"
causes a syntax error. According to https://docs.python.org/3/whatsnew/3.3.html?highlight=unicode, that syntax was added back in Python 3.3.
For the benefit of others, may I suggest that your Github README.md be updated to read "Works with Python 2.7 and 3.3" instead of "Works with Python 2.7 and 3"?
I tried your second suggestion in an interactive terminal. But even the line from pytg.encoding import to_unicode as u
causes the following syntax error immediately:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pytg/__init__.py", line 9, in <module>
from .encoding import to_unicode as u
File "pytg/encoding.py", line 36
return u"\\"
^
SyntaxError: invalid syntax
I'm not an avid Python programmer, so it sounds like I'm better off sticking with Python 2.7 for now, on the Raspberry Pi.
from pytg.
# now just change the
u"stuff" #python 2 (and python 3.3+)
# to
"stuff" # python 3.0+
# or, after importing
from pytg.encoding import to_unicode as u
# to
u("stuff") # all pythons
But I'll add that. Actually only the examples are not python 3.0-3.3 compatible, pytg itself is.
from pytg.
I don't understand. The syntax error is not happening in my script or even the setup.py
script. It is happening in encoding.py itself, in the very to_unicode function that you suggest I import as 'u'. It won't even import, because right there Python 3.2 shows the syntax error.
Now, assuming you meant modifying lines 33 and 34 in your encoding.py (replacing b'' with '' and replacing u"" with ""), this at least allows sudo python3 setup.py install
to succeed. But ultimately, when I run my own script to use pytg, I just get more of the same syntax errors in the DictObject/encoding.py instead (which looks almost identical to yours).
from pytg.
Ohh.
I thought that were the example files.
Can you check if it works, if you remove line 33 to 34 in encoding.py?
(The if x == b'\\':
part)
from pytg.
Yes, that seems to do the trick. It's a workaround, at least.
I removed lines 33-34 in pytg/encoding.py
:
if isinstance(x, binary_type):
#if x == b'\\':
# return u"\\"
return x.decode("utf-8")
That solves the original error. But I just get the same error for DictObject instead. So I also removed lines 30-31 in /usr/local/lib/python3.2/dist-packages/DictObject-0.1.1-py3.2.egg/DictObject/encoding.py
:
if isinstance(x, binary_type):
#if x == b'\\':
# return u"\\"
return x.decode("utf-8")
Now, everything works in the script that I built to use pytg. For your ping example to work, though, I must edit examples/ping.py and replace all uses of u"........"
with "........"
(lines 57,58,59,61,64).
Thanks for your help! This is the first time I've ever worked with Unicode in Python, so I wasn't sure at first what I was even looking at or why the syntax errors were occurring. Now, to continue my Raspberry Pi project... :)
from pytg.
Your welcome. I will update pytg as well as DictObject (and several other projects where I use that file) to reflect that.
from pytg.
It should now be fixed.
If importing luckydonaldUtils
fails, install it with pip install luckydonald-utils
manually.
from pytg.
Related Issues (20)
- Error in sending message - Error 38: 'can not parse arg #1' with [disable_preview] HOT 7
- how to get Post ID after sending to channel HOT 1
- Problem With bad Internet HOT 1
- is any command for "delete all from this user" HOT 2
- Reply keyboard HOT 1
- Usage with asyncio HOT 1
- no event for message received in channel HOT 3
- error with fwd_media HOT 1
- NoResponse: [disable_preview] load_document HOT 2
- pytg: INFO CLI did not responde HOT 1
- Telegram.stop_cli() function doesn't work HOT 13
- get rid of DictObject HOT 2
- Using multiple if checks in bot_ping.py results in check failure HOT 1
- ERROR 'RPC_CALL_FAIL 401: AUTH_KEY_UNREGISTERED' HOT 1
- How can I know my telegram-cli account is blocked or not authorized? HOT 2
- sender.history() doesn't work HOT 1
- result_parser.py line 28
- How to keep a CLI already running in json mode on port 4458 ? HOT 2
- Retrieve caption of a sended document? HOT 1
- Result parser for secret chats raises exception due to expected result in JSON HOT 1
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 pytg.