Shared publicly  - 
 
python pain.

why do i get a syntax error in the following?

# traverse the dir, remove temp files
for dpath, dirList, fileList in os.walk(inPath, topdown=False):
    for ff in fileList:
        if (ff == ".htaccess") or \
                (ff == ".DS_Store") or \
                re.search(r"^xx", ff) or \
                re.search(r"^#.+#$", ff) or \
                # re.search(r"~$", ff) or \
                re.search(r"^xx", ff):
            print("◆", ff)

File "/home/xah/git/xahscripts/make_download_copy/delete_temp_files.py3", line 46
    # re.search(r"~$", ff) or \
                              ^
SyntaxError: invalid syntax

if you remove the comment, then it's fine.

seems like a syntax BUG!
1
Rat Xue's profile photoAndrew Kirkpatrick's profile photoDanis V.'s profile photoWang Bin's profile photo
18 comments
Rat Xue
 
Why do you torture yourself with python?
Xah Lee
+
1
2
1
 
+Rat Xue well one can't always live in a ideal world...

i knew perl well, but it's worse than python in general, and it's slowly going away. I like ruby better, but don't know it well, and far less popular today, not installed by default. I love and know Mathematica well, but it's rather not suited for sys admin scripts like this, and it's been long time i coded M, don't even have the current version. Some thousand dollars.... then, i needed to be fluent with one to demo to interviewers, so doing in python helps in interview.
Xah Lee
 
what would you suggest? and what langs do you use?
Rat Xue
+
1
2
1
 
I would suggest someone just hire you knowing that picking up enough of a language to solve a work problem is trivial for you. C and a lisp are still all you need. I'm going through a similar thing with C++ and am disheartened by the nonsense that comes up in interviews. Plus les choses changent plus elles restent les mêmes.
Rat Xue
 
un canard avec des ciseaux --> a cow with a gun
Translate
 
+Xah Lee  from http://docs.python.org/2/reference/lexical_analysis.html#explicit-line-joining:

A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals (i.e., tokens other than string literals cannot be split across physical lines using a backslash). A backslash is illegal elsewhere on a line outside a string literal.

BTW, I think a more pythonic way to check is:

for pattern in (r'^\.htaccess$', r'^\.DS_Store$', r'~$', r'^xx'):
        if re.search(pattern, ff):
            print ff
 
The "Perl is dying" meme is itself dying since in recent years there has been a renaissance of modern Perl sites, tools and modules, regular releases (5.18 is due out soon) and a sister/successor language in Perl6 with two implementations getting close to passing the suite of 24,000 spec tests.
http://blogs.perl.org/users/ovid/2013/01/economics-101.html
Xah Lee
 
+Andrew Kirkpatrick i don't think it'll save perl. Perl6 has been around almost a decade. the new engine Parrot, seems also dying, and nobody really cares.
 
Python was about ten years old before many people cared. Parrot only needs one use case to make it worthwhile and that is rakudo. Niecza shows that perl6 doesn't depend on parrot, and if there's a C# implementation then porting it to the JVM isn't rocket surgery. http://perl6.org/compilers/features
Xah Lee
 
+Andrew Kirkpatrick yeah, but that can be said for all other langs.

especially these days, langs are a dime a million. http://xahlee.info/UnixResource_dir/writ/new_langs.html

perl had its day, people got tired of the mongering shit.

I think you are rather a perl fan?

despite our wishes and hopes, i myself am very happy if perl dies a horrible death. It was perl, that started 99% of web not being html valid. cgi.pm. It was perl, lied thru its teeth about y2k compliance. its lies and sophistries eventually runs out of juice, and started to shrivel starting post dot com. First, php, a lang that's based on perl but without and fancy talk yet truly practically and useful doc, quietly surpassed perl around 2005. Then, python arose, thank to google. Why didn't google pick perl? of course, its syntax is garbage plus intentional obfustication. Then ruby arose with Rails. Ruby is actually even higher level than python. Python, to my chagrin, turns out to be cult-like, due to Guido himself being a sorta crank, hates functional lang, pushes hard for python to be edu, yet, python's doc, and the lang itself, is nothing close to simple.
 
+Xah Lee that was an interesting and somewhat disheartening post by Chromatic, but the work on Rakudo has been extensive and fundamental since he wanted to use it in production in 2010. Were the current governance of Parrot to fold, the Rakudo project would have to take up the reins. Trying to get along with any online community can be difficult, especially when you have business needs hinging on it.
I like Python in theory but its anti-functional warts are frustrating, and I've yet to see a compelling feature of Ruby to draw me away from Perl5. Everything except Lisp seems to have rubbish syntax.
I'm not so much a Perl fan as a user that finds comments on its decline to not be reflected in real world experience :)
 
You’re doing it wrong. In Python, you are not supposed to join lines with backslash except in dire circumstances; instead, you open a parenthesis and indent the subconditionals.

        if (ff == ".htaccess" or
                ff == ".DS_Store" or
                re.search(r"^xx", ff) or
                re.search(r"^#.+#$", ff) or
                # re.search(r"~$", ff) or
                re.search(r"^xx", ff)):
            print("◆", ff)
 
have you see construction like this working in other languages? i'm not understanding why you wonder(asking). liked the pythonic way above =)
 
In C/C++, backslash/newline is valid in comment, and/but the comment continues, so the corresponding construct wouldn’t work.
In sh/bash/dash and Perl, the comment spans only until end of physical line.
In Python, backslash in comment is illegal but not all versions enforce this rule consistently.

Until recently, the C++ standard said that a file included with #include SHALL end in a newline (or welcome to Unexpected Behavior land). This indicates there probably existed an implementation in which a comment started in one file could continue in another.

All this shows one must be very careful when mixing line-end comments with line splicing.
Add a comment...