Python Forum
Uncanny line of code in Torchat source file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uncanny line of code in Torchat source file
#2
config_defaults is a dict that has tuples as keys.
And in this line value = config_defaults[section, option] section, option part is implicit tuple, so it's a valid code, effectively the same as value = config_defaults[(section, option)].

from the docs:
Quote:output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway (if the tuple is part of a larger expression).

>>> foo = 'spam', 'eggs'
>>> foo
('spam', 'eggs')
>>> type(foo)
<class 'tuple'>
>>> 
also, another example:


some_dict = {(1, 2):'one',
             (3, 4):'two'}
print(some_dict[1, 2])
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Uncanny line of code in Torchat source file - by buran - Jan-05-2019, 10:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  delivery exe without source code py loky62 2 406 Apr-04-2024, 05:47 PM
Last Post: loky62
  Algorithm for extracting comments from Python source code Pavel1982 6 675 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Unable to understand the meaning of the line of code. jahuja73 0 355 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 7,290 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,735 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 911 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,739 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,449 Sep-27-2022, 01:38 PM
Last Post: buran
  Print to a New Line when Appending File DaveG 0 1,249 Mar-30-2022, 04:14 AM
Last Post: DaveG
  Find and delete above a certain line in text file cubangt 12 3,642 Mar-18-2022, 07:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020