-3

I have inherited a set of Python code, and I think I know the answer to this, but wish to be sure.

It looks like both #s and --s are used interchangeably throughout the code to signify comments but any searches I am doing do not yield information about using the --.

I used to do the --s within Teradata a long time ago. Am I missing something?

Adding in some additional information too: I am running the code within Spyder (Python3.6). Perhaps that will shed more light on what is going on.

Below is an example of the -- seeming to work:

qry = """
select s2019.sk2019,
s2018.sk2018
from (select distinct h1.key sk2019,
e.Territory Territory2019 from cdw.fact_header
left join cdw.dim_event e on h1.event = e.event
where e.sy in (2019)
and e.program_name = 'xyz'
and a.Country = 'USA'
-- and h1.code = 'DC'
and h1.key > 0
Zach
  • 37
  • 8
  • 2
    Have you run this code to verify that it executes properly? If I try running code on my machine that has "--" style comments as you described, I get a SyntaxError. – Kevin Sep 10 '18 at 13:54
  • 1
    Sometimes [triple quotes are used for multi-line comments](https://stackoverflow.com/q/7696924/190597). So the `--` at the start of the line could just be part of a multiline triple-quoted comment. – unutbu Sep 10 '18 at 13:57
  • `#` indicates comments in Python. `--` indicates comments in SQL. – khelwood Sep 10 '18 at 14:01

1 Answers1

2

One line comments are done using the # while multiline comments are done using the triple-quote

""" Text here 
and here"""

the -- comment is used in sqlite with python. Do you have that comment inside a query that is also written inside a string/triple-quote comment? Like:

""" SELECT * FROM TABLE
--WHERE N = X"""

UPDATE 1: Here you can see and example of comment inside the query done in a python code

query = """ SELECT * FROM TABLE
--WHERE N = X"""

By putting -- inside the query, before WHERE I've made everything that follows ignored. So when the query is executed I will only execute the first line of the query.

  • Sorry could you edit your comment and use the formatting by putting ` at the begining and the end of the code? You can click the help button below add comment to see the formatting that can be applied – Alexandru Martalogu Sep 10 '18 at 14:43
  • In your query the only part of the query that will not be executed is the part you commented with `--`, so you just removed the condition where `h1.code`has to be `'DC'` – Alexandru Martalogu Sep 10 '18 at 14:48
  • Thank you. I was worried that my line saying and h1.key > 0 would be ignored too since it follows the preceding line that begins with --. – Zach Sep 10 '18 at 14:56
  • Everything that is on the same line as `--` will be ignored, otherwise, it's good to go. – Alexandru Martalogu Sep 10 '18 at 14:57