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).
Related
How can I make VS code detect incorrect argument names?
def test_function(name1, name2, name3):
print(name1)
print(name3)
print(name2)
test_function(name1=1, name2=2, name4=4)
Currently, VS code doesn't flag this as an error. Detecting this would be very useful since argument names change. Otherwise you get an error at run time which is far too late.
VS code is a text editor that one can use to write code in multiple languages but is not a Python interpreter. What you can do is install an extension to do that. For example: Python from Microsoft, has a linter that shows you what problems your code has, including the kind of problem you're describing. Make sure you read the docs to configure it correctly.
Some odd reaction with PyQt5.8 on windows 10. I'm making this because I want to try to understand why I get this problem, as it's easily solved. (Shown below)
I try to do:
Command =''' testurl -x --audio-format "mp3" --audio-quality "0"'''
self.start('yotube-dl',Command.split())
but get the error from youtube-dl that the specified audio format is wrong. Which means that for some reason, "mp3" isn't after --audio-format. I also tried, --audio-format="mp3", and that also gives me an error, despite not having a space after the --audio-format
Now, if I do my "workaround":
self.start('youtube-dl'+Command)
It works as expected. It tells you the specified URL(since it's testurl) is not valid. Don't be mistakes, a working url behaves just the same. So, obviously one would think there's something funky with the .split() part of it, but this is how the list turns out when you use Command.split():
['testurl', '-x', '--audio-format', '"mp3"', '--audio-quality', '"0"']
And as far as I know, the arguments are passed in order of the list. I've had it working before, but as soon as I changed another configuration, it all went south. I just can't figure out why my results differ, and it's only for this specific audio conversion argument(-x --audio-format "mp3"), other arguments work pretty well, one of them containing spaces.
Also, I can let you know I tried with lots of "'s around in the string, and to no help. I'm presuming this has something to do with the way " are added in some places on windows according to Qt documentation(Link for reference), but I still can't make figure out what to change. For all I know, it's something stupid i'm doing.
So, if anyone has understanding of why it does this, i'd love to know. Again, i'm just looking for some clarity, as I already worked around it, but want to understand why it goes wrong.
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.
I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.
I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent.
Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?
There's also Ctrl+n in insert mode which will autocomplete based on the words it has seen in any of the open buffers (even in other tabs).
You may try Pydiction (Excerpt below)
Description Pydiction allows you to
Tab-complete Python code in Vim,
including: standard, custom and
third-party modules and packages. Plus
keywords, built-ins, and string
literals.
Pyflakes has a vim plugin that does this pretty awesomely. Unlike Pydiction, you don't need to build a dictionary beforehand (so if you're bouncing between different virtualenvs it's a bit less hassle.) I haven't been using it long but it seems very slick.
Try hitting Ctrl-p while typing mid-word. Ctrl-p inserts the most recent word that starts with the prefix you're typing and Ctrl-n inserts the next match. If you have several possibilities, you can hit ctrl-p more than once to substitute each candidate in order.
I have been banging my head against the keyboard in search of enlightenment through Google and all Python docs I could get my hands on, but could not find an answer to an issue I'm encountering.
I have the following regex that I run against a website, but Python insists in setting re.DOTALL on it, even though my code does not tell it to:
\d+. +(?P<season>\d+) *\- *(?P<episode>\d+).*?(?P<day>\d+)(?:\/|\s)+(?P<month>[A-Za-z]+)(?:\/|\s)+(?P<year>\d+) +(?:<a .+><img .+></a>)? ?<a .*?>(?P<name>.*?)</a>
This creates an array of seasons/episodes for TV show listings, and it works fine except on epguides.com/BurnNotice (when using the TVRage listings), due to some spacing before newlines (I guess).
Using http://re-try.appspot.com to test, I've narrowed down the issue to the use of re.DOTALL. If I enable it on re-try, it replicates the results I get when I run it standalone on my script. If I untick DOTALL, then it gives me the results I expect.
How can I force Python NOT to use re.DOTALL?
The script runs both on Ubuntu and OS X.
.+> should change to [^>]+> and
.*?> to [^>]*>
You can try replacing others dots into [^\r\n] too, but above 2 changes should be enough.