Here it's important to use context manager (the 'with' statement), otherwise, in case of exception the file won't be closed.
Something like that will look better:
with open(str(path+name+extension), "w") as out_file:
for keys in data["Measurements"]:
....
The line out_file.close() is not needed.
*Created by: ivan-usov*
Here it's important to use context manager (the 'with' statement), otherwise, in case of exception the file won't be closed.
Something like that will look better:
```
with open(str(path+name+extension), "w") as out_file:
for keys in data["Measurements"]:
....
```
The line `out_file.close()` is not needed.
But I would also suggest you to have a look at f-strings, which appeared in python/3.6. They could be even easier to use in this case.
*Created by: ivan-usov*
In fact, there are similar padding options in `str.format()` function. Basically, all of the following have similar output:
```
fill_string('asdf', 10)
'asdf'.rjust(10)
'{:>10}'.format('asdf')
```
But I would also suggest you to have a look at f-strings, which appeared in python/3.6. They could be even easier to use in this case.
if data["meta"]["indices"] == "hkl":
extension = ".comm"
elif data["meta"]["indices"] == "real":
extension = ".incomm"
with open(str(path + extension), "w") as out_file:
for keys in data["Measurements"]:
if extension == ".comm":
meas_number_str = fill_string(keys[1:], 6)
...
else:
meas_number_str = fill_string(keys[1:], 4)
...
etc.
Or something like that, probably the final form will be different depending on the approach you choose with the string interpolation.
*Created by: ivan-usov*
This code needs to be deduplicated.
```
if data["meta"]["indices"] == "hkl":
extension = ".comm"
elif data["meta"]["indices"] == "real":
extension = ".incomm"
with open(str(path + extension), "w") as out_file:
for keys in data["Measurements"]:
if extension == ".comm":
meas_number_str = fill_string(keys[1:], 6)
...
else:
meas_number_str = fill_string(keys[1:], 4)
...
etc.
```
Or something like that, probably the final form will be different depending on the approach you choose with the string interpolation.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Created by: JakHolzer
Created by: ivan-usov
Here it's important to use context manager (the 'with' statement), otherwise, in case of exception the file won't be closed.
Something like that will look better:
The line
out_file.close()is not needed.Created by: ivan-usov
These lines should be removed, while
pathandnameshould become a function argument (probably, a single one).Created by: JakHolzer
Deleted, changed to path argument which should be str(path+name) - or wold you rather pass it as a touple?
Created by: JakHolzer
done :)
Created by: ivan-usov
You can use
str.rjustfunction instead (https://docs.python.org/3/library/stdtypes.html#str.rjust)Created by: ivan-usov
In fact, there are similar padding options in
str.format()function. Basically, all of the following have similar output:But I would also suggest you to have a look at f-strings, which appeared in python/3.6. They could be even easier to use in this case.
Created by: ivan-usov
This code needs to be deduplicated.
Or something like that, probably the final form will be different depending on the approach you choose with the string interpolation.
Created by: JakHolzer
I deduplicated the code and used the fstrings to do the padding
Created by: ivan-usov
Review: Approved
Merged by: ivan-usov at 2020-09-15 12:24:34 UTC