Skip to content

Commit

Permalink
remove f-strings (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamHPNielsen committed Dec 14, 2017
1 parent 3ff3710 commit efee2ff
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions qcodes/utils/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
if sys.version_info < (3, 6):
raise RuntimeError('Magic only supported for Python version 3.6 and up')


@magics_class
class QCoDeSMagic(Magics):
"""Magics related to code management (loading, saving, editing, ...)."""
Expand Down Expand Up @@ -82,11 +83,10 @@ def measurement(self, line, cell=None):
data_name = options.get('d', 'data')
loop_name = options.get('l', 'loop')


lines = cell.splitlines()
assert lines[0][:3] == 'for', "Measurement must start with for loop"

contents = f'import qcodes\n{loop_name} = '
contents = 'import qcodes\n{} = '.format(loop_name)
previous_level = 0
for k, line in enumerate(lines):
line, level = line.lstrip(), int((len(line)-len(line.lstrip())) / 4)
Expand All @@ -99,7 +99,7 @@ def measurement(self, line, cell=None):
continue
else:
line_representation = ' ' * level * 4
if level < previous_level :
if level < previous_level:
# Exiting inner loop, close bracket
line_representation += '),' * (previous_level - level)
line_representation += '\n' + ' ' * level * 4
Expand All @@ -109,13 +109,16 @@ def measurement(self, line, cell=None):
for_opts, for_code = self.parse_options(line[4:-1], 'd:')
if 'd' in for_opts:
# Delay option provided
line_representation += f'qcodes.Loop({for_code}, ' \
f'delay={for_opts["d"]}).each(\n'
line_representation += ('qcodes.Loop({}, '
'delay={}).each(\n'
''.format(for_code,
for_opts["d"]))
else:
line_representation += f'qcodes.Loop({for_code}).each(\n'
line_representation += ('qcodes.Loop({}).each(\n'
''.format(for_code))
else:
# Action in current loop
line_representation += f'{line},\n'
line_representation += '{},\n'.format(line)
contents += line_representation

# Remember level for next iteration (might exit inner loop)
Expand All @@ -124,7 +127,9 @@ def measurement(self, line, cell=None):
# Add closing brackets for any remaining loops
contents += ')' * previous_level + '\n'
# Add dataset
contents += f"{data_name} = {loop_name}.get_data_set(name='{msmt_name}')"
contents += "{} = {}.get_data_set(name='{}')".format(data_name,
loop_name,
msmt_name)

for line in lines[k+1:]:
contents += '\n' + line
Expand Down Expand Up @@ -154,6 +159,6 @@ def register_magic_class(cls=QCoDeSMagic, magic_commands=True):
if magic_commands is not True:
# filter out any magic commands that are not in magic_commands
cls.magics = {line_cell: {key: val for key, val in magics.items()
if key in magic_commands}
if key in magic_commands}
for line_cell, magics in cls.magics.items()}
ip.magics_manager.register(cls)
ip.magics_manager.register(cls)

0 comments on commit efee2ff

Please sign in to comment.