This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Bug in editor.make_new_path() when using absolute path.
rhithyn last edited by
I think I've found a bug with editor.make_new_file. If an absolute path is given, it will just crash with an "undeclared variable before use" error.
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "/var/containers/Bundle/Application/97D3CA1E-BD16-4F1A-B952-153773020E29/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 1064, in OMMainThreadDispatcher_invoke_imp
retval = func(*args, **kwargs)
File "/var/containers/Bundle/Application/97D3CA1E-BD16-4F1A-B952-153773020E29/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/editor.py", line 124, in make_new_file
full_path = os.path.join(doc_path, new_name)
UnboundLocalError: local variable 'doc_path' referenced before assignment
If I get the path of the current editor file, and pass it into make_new_file (which should make a number-incremented file in the same folder), it fails.
I have an idea for a workaround (parsing the path down to the "Documents" folder and using that path) but wanted to give a heads up about this bug.
omz last edited by
Thanks, this should be fixed in the next beta/release.
This bug only occurs if a file with the given name already exists, so if you want to work around it for now, you would have to find a non-existing name yourself, e.g. like this:
full_path = ... # Assuming you have a full path already # Make sure that the file doesn't exist yet: directory, filename = os.path.split(full_path) suffix = 1 while os.path.exists(full_path): base_name, ext = os.path.splitext(filename) new_name = '%s_%i%s' % (base_name, suffix, ext) full_path = os.path.join(directory, new_name) suffix += 1 # Now we can safely call make_new_file: editor.make_new_file(full_path)
dixita last edited by
Hello.. i also faced same as above.. n just solved.. thnx buddy