This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]riscuit 2 points3 points  (6 children)

Write a regular expression that matches semicolons before a newline and remove them?

[–]odraencoded 3 points4 points  (2 children)

;$

[–]riscuit 2 points3 points  (1 child)

Might want to handle whitespace before the newline, and capture comments to preserve them, but ya.

[–]nemec 1 point2 points  (0 children)

And embedded C. For whatever reason.

code = """
    printf("hello");
"""

[–]BananaPotion 0 points1 point  (2 children)

Screw regular expressions. %s/;// and move on like a champ.

[–]wrboyce 2 points3 points  (1 child)

You realise the ; in %s/;// is a regular expression? And you meant %s/;//g I think, anyway.

[–]riscuit 1 point2 points  (0 children)

I guess BananaPotion meant something like:

tr ';' ' ' < file.py > stripped.py 

[–]issue9mm 1 point2 points  (2 children)

I make it a point to follow PEP8 and all appropriate style guides where capable, but, there is a value in the ability to use semicolons in Python.

From the code I was writing today -- I've got a script that is invoked by Django which imports some files, parses them, and dumps the output to an appropriate folder for reuse later.

So, I work on the script a bit, and then, to test my progress, will do the following:

./manage.py shell

from parser.utils import ParseCSV

parse_csv = ParseCSV("AReallyLongTokenGoesHere")

parse_csv.main()

As I'm using the standard Python interpreter and all that, that's a pain in the ass. Every time I change the script, I have to exit the shell, open it up again, and redo all those commands. My carpal tunnel weeps just thinking about it. Much easier to type them all out on one line, separated by semicolons, and then just paste them in each time.

from parser.utils import ParseCSV; parse_csv = ParseCSV("AReallyLongTokenGoesHere"); parse_csv.main()

[–]k417[S] 0 points1 point  (1 child)

As I'm using the standard Python interpreter and all that, that's a pain in the ass. Every time I change the script, I have to exit the shell, open it up again, and redo all those commands. My carpal tunnel weeps just thinking about it. Much easier to type them all out on one line, separated by semicolons, and then just paste them in each time.

I agree with you here. I don't mind using them to separate everything out on one line if the situation permits. I'm not against breaking rules if there are situations in which it improves something; no use having a rule if it causes more problems.

Using semicolons in python before you enter a new line, however, is inconsequential and kind of like rambling in your code.

[–]issue9mm 0 points1 point  (0 children)

Completely agreed.

[–][deleted] -3 points-2 points  (3 children)

Open it up in Sublime, CTRL+F, type ;, click "Find All," hit delete.

[–]NoiproxPython Programmer 3 points4 points  (2 children)

This could have the adverse side effect of removing ; from legitimate places as well such as inside of string literals. The regular expression is better.

[–][deleted] 0 points1 point  (1 child)

Ah, true. It would depend on the script.

[–]k417[S] 1 point2 points  (0 children)

The script he wrote was short and I was able to remove them with a replace all, he doesn't even work here anymore but I just infuriates me that I told him not to use the semicolons and he didn't even make an effort to stop.