I obfuscated my python 3.5 code and now I am left with these strange black boxes. I am not able to copy them and "search and replace" with some character. How am I supposed to get rid of them? The code won't run, it keeps raising "syntaxError: invalid character in identifier"
This is very frustrating I have been stuck with this issue for hours.
If you use Notepad++, you can use the HEX-Editor plugin and view the raw hex of your source, and then use Ctrl+H to find and replace "A6" with whatever you desire.
If you do not have that plugin, it's very easy to download it using Notepad++'s built in plugin manager.
The extended ASCII Tables tell me that 0xA6 is a broken vertical bar, which certainly doesn't seem like a valid character for an identifier, so no questions there.
Related
I'd rather avoid using curses for this, largely because of how much curses screws with the terminal by default. Frankly, using window.inch() in curses has not worked correctly in most situations, anyway, so it doesn't seem worth working through all the echo, newline, and other issues with curses to get that function.
I need to be able to read the value of a character at some position on the terminal. I don't particularly care if unicode characters work or if I get info about the character attributes (like underline, bold, color, etc.) though it would be nice.
Thanks...
I got bbcodepy and I'm allowed to modify it, but I can't import it in my main.py. I keep getting a SyntaxError and I don't really know what's wrong with the code because I didn't write it. I just want to tinker around a little bit and see if I can get it to fill my needs.
Here's an image pointing me in the direction of the syntax error. But I noticed the same code is written on the same line and I don't get the SyntaxError for that. Here's the code:
_URL_RE = re.compile(ur'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?#\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)''')
The problem appears to be "[^\s&()]" but only the second one, not the first one. If you look closely in the code you'll see that the same thing appears twice, but I only get the SyntaxError on the second appearance. Someone enlighten me, please. I've been trying to find a decent BBCode parser for Python for a couple of days now and I believe this is the one I can modify to my needs. I can't seem to get bbcode to work as I want it to, so I'm trying this out.
Well, Python version 3.4 and above does not support a 'UR' prefix.
You need to execute your code with Python 2.7, or change to line into:
_URL_RE = re.compile(r'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?#\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)''')
See also: python version 3.4 does not support a 'ur' prefix
Note: consider avoiding triple-quoted string because if you insert a newline, it can change the meaning of the regex (unless it is compiled in VERBOSE mode).
The Unicode character U+1d134 is the musical symbol for "common time"; it looks like a capital 'C'.
But using Python 3.6, when I specify '\U0001d134' I get a glyph that seems to indicate an unknown symbol. On my Mac, it looks like a square with a question-mark in it.
Is the inability to display the corresponding glyph simply a font limitation, or is it something else? (Like maybe something I'm doing wrong....)
For clarity, I want to use this and other such symbols in an app I'm writing, and would like to find out if there's a way to do this.
The problem lies not in your code but in your local system. You don't have any font installed that contains the character 𝄴 "MUSICAL SYMBOL COMMON TIME".
That is also the reason none of your browsers can display it. Usually, browsers are quite good in hunting down any font that can display a certain character. Reason they all fail is what's in the paragraph above.
But – as it happened,
>>> print ('\U0001d134')
𝄴
worked for me, displaying this:
I pasted it into UnicodeChecker, which helpfully listed 'all' fonts that contain this character: only one, Bravura. It's an Open Source font so go ahead and download it. (Be careful to follow proper procedures if you want to distribute it along with your app.)
To think that I only had that font installed because of an earlier SO question.
I have a Logitech 360 keyboard, with which I am trying to code Python on the Raspberry Pi B. The apostrophe key produces a slanted quote, instead of the 'vertical' single quote, and this causes syntax errors in code (the same code runs perfectly when I paste in a snippet from the browser, which is the only way I can find to produce the correct flavor of apostrophe).
The syntax error is "Non-ASCII character '\xc2' in file '---' on line X, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details." The webpage suggests declaring a character encoding at the beginning of the script, but it didn't work for me, and in any case, I would rather not have to have it at the beginning of every script - I just want the keyboard to produce the correct character to begin with. I have fiddled with the keyboard config international settings; nothing works. It's driving me nuts.
you cannot use "\xc2" as a quote character without redefining the quote character in python source grammar(really your problems extend beyond even this) and recompiling python ....
you probably can change what character your logitech uses as a quote
You may want to check your Internationalisation Options by running
sudo raspi-config
Choose Option 4 - Internationalization Options
and then Option I3 - Change Keyboard Layout
Go through and check your settings and then try your keyboard again.
Coming from Perl I've been used to hitting C-c t to reformat my code according to pre-defined Perl::Tidy rules. Now, with Python I'm astonished to learn that there is nothing that even remotely resembles the power of Perl::Tidy. PythonTidy 1.20 looks almost appropriate, but barfed at first mis-aligned line ("unexpected indent").
In particular, I'm looking for the following:
Put PEP-8 into use as far as possible (the following items are essentially derivations of this one)
Convert indentation tabs to spaces
Remove trailing spaces
Break up code according to the predefined line-length as far as it goes (Eclipse-style string splitting and splitting method chains)
Normalize whitespace around
(bonus feature, optional) Re-format code including indentation.
Right now, I'm going throught someone else's code and correct everything pep8 and pyflakes tell me, which is mostly "remove trailing space" and "insert additional blank line". While I know that re-indentation is not trivial in Python (even though it should be possible just by going through the code and remembering the indentation), other features seem easy enough that I can't believe nobody has implemented this before.
Any recommendations?
Update: I'm going to take a deeper look at PythonTidy, since it seems to go into the right direction. Maybe I can find out why it barfs at me.
There is a reindent.py script distributed with python in the scripts directory.
untabify.py (Tools/scripts/untabify.py from the root directory of a Python source distribution) should fix the tabs, which may be what's stopping Python Tidy from doing the rest of the work.
Have you tried creating a wrapper around pythontidy? There's one for the sublime editor here.
Also, does pythontidy break up long lines properly for you? When I have a long line that ends in a tuple, it creates a new line for every entry in the tuple, instead of using Python's implied line continuation inside parentheses, brackets and braces as suggested by PEP-8.
I have used autopep8 for this purpose and found it handy.