Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

New file creation using Python is containing special character

>>> with open('/home/amitsh/PYTHON/AZURE/logs/ud_final_id.txt', 'r') as ciid:
...   for udcid in ciid:
...     open(f"/home/amitsh/PYTHON/AZURE/logs/UDID/{udcid}","w")
... 
<_io.TextIOWrapper name='/home/amitsh/PYTHON/AZURE/logs/UDID/4f552eb733e2a8aaa2f1950bef6efac7\n' mode='w' encoding='UTF-8'>
<_io.TextIOWrapper name='/home/amitsh/PYTHON/AZURE/logs/UDID/4a81a02538598bd4b90f57ed75457e5b\n' mode='w' encoding='UTF-8'>
<_io.TextIOWrapper name='/home/amitsh/PYTHON/AZURE/logs/UDID/4af35b87154d5d4aab6b8637dcd6b7be\n' mode='w' encoding='UTF-8'>
<_io.TextIOWrapper name='/home/amitsh/PYTHON/AZURE/logs/UDID/470031350886ba1f91d6e23d09cf4186\n' mode='w' encoding='UTF-8'>
<_io.TextIOWrapper name='/home/amitsh/PYTHON/AZURE/logs/UDID/4826f82391df0920bc0891cebfb52462\n' mode='w' encoding='UTF-8'>
[root@XXXX UDID]# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Mar 13 19:12 4f552eb733e2a8aaa2f1950bef6efac7?
-rw-r--r--. 1 root root 0 Mar 13 19:12 4a81a02538598bd4b90f57ed75457e5b?
-rw-r--r--. 1 root root 0 Mar 13 19:12 4af35b87154d5d4aab6b8637dcd6b7be?
-rw-r--r--. 1 root root 0 Mar 13 19:12 4826f82391df0920bc0891cebfb52462?
-rw-r--r--. 1 root root 0 Mar 13 19:12 470031350886ba1f91d6e23d09cf4186?
-rw-r--r--. 1 root root 0 Mar 13 19:12 489a46b15e1edb488544ab383887e2d2?
-rw-r--r--. 1 root root 0 Mar 13 19:12 47b25e62090aff7280c1973c60764ef1?

The new files are having question mark "?" due to which the program is not running.
Need your support in managing this issue.

I need these files to put data which is gathered from API’s.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you loop over a file’s lines, you’ll also get the trailing newline, which ls represents as a ?.

After for udcid in ciid:, add udcid = udcid.strip() to strip all surrounding whitespace from the line you’ve read.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading