doc_holder_str = ''
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
standard_conc_value = open("C:\testGupixwin\gupixwin_H_stdConc.txt", "r")
sample_H_value_str = sample_H_value.readline()
while sample_H_value_str is not '' :
stripper_sample_H = float(sample_H_value_str[5:].lstrip(' '))
I'm trying to write a piece of code (as shown above) which reads some values, do some calculations on it and returns the said values. I am using the LiClipse IDE, for python.
I have tested my code and it works, but when I tried to run it with real data, ( for which I created a new folder to put in all the files I will be working with) I received an OS error suggesting I inserted an invalid argument.
The error report says ;
Traceback (most recent call last):
File "C:\Python34\workspace\Gupixwin_Project.py", line 11, in <module>
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
OSError: [Errno 22] Invalid argument: 'C:\testGupixwin\\BX-N-H.HED'
on clicking on the C:\testGupixwin\\BX-N-H.HED it bring up a message box suggesting, and I quote,
The definition was found at C:\testGupixwin\BX-N-H.HED, (which
cannot be opened because it is a compiled extension)
I must point out that I feel the error is that the system sees ...\\BX-N.... Instead of ..\BX-N... Which I expect.
Some one suggested I do this
[Open Window -> Preferences, goto PyDev -> Editor -> Code Style ->
File Types, look for "Valid source files (comma-separated)" and append
", log".]
I HAVE DONE THIS BUT I STILL GET THE OSERROR REPORT.
Thanks for any assistance
I think the problem is the escaping with \
alternate the string in: open("C:\testGupixwin\BX-N-H.HED", "r")
with:
open( r"C:\testGupixwin\BX-N-H.HED", "r" ) #rawstring
# or
open( "C:\\testGupixwin\\BX-N-H.HED", "r" ) #escaping the '\' with '\'
(also do this in the following line)
Related
I am trying to convert msg file to pdf using Convert.ToPdf(doc, filename).
The .docx to pdf conversion is done properly using this function, however, I am only getting an error while converting msg to pdf.
The 'print' option is also there in the context menu when I right click on the file.
This is the error I am getting:
PDFNet is running in demo mode.
Traceback (most recent call last): File "test.py", line 58, in
main() File "test.py", line 44, in main Convert.ToPdf(doc,
filename)
Exception: An error occurred while converting the file.
Detailed error: Exception: Message: Unable to find printer Conditional
expression: success Version : 8.1.0.30521 Platform : Windows
Architecture : AMD64 Filename : Convert.cpp Function :
trn::PDF::ToPdfPrinterManager::InitPrinter Linenumber : 776
printing to printer \trial_msg.msg AssocQueryString printto:
AssocQueryString print : "C:\Program Files\Microsoft
Office\Root\Office16\OUTLOOK.EXE" /p "" Created new PDFNet Mutex
WaitForSingleObject start WaitForSingleObject End printo:
/Local/Temp/pdftron/Trn-17236-1616513476-af5adf11-bd4d-4d40-beec-8f6aad996f18.xps
Using HKCU Return value for delete registry: 0 Return value for delete
registry: 0 Return value for release mutex: 0 Return value for close
mutex: 0 Error destructing ToPdfPrinterManager
The next release of PDFNet, 9.0, will use Outlook interop to do the MSG conversion, instead of the less reliable printto command line option.
I am Following Chris P's 'Visualize Real-world JSON Data in Blender (3D Chart Animation Nodes Tutorial)' on YouTube but I seem to have got stuck at the first hurdle of importing the data. I have followed his instructions completely and am unsure why the script keeps failing. I have attached his script, My script, my file location, my error message and a snap shot of his video. I am On windows OS, he is on Linux I'menter image description here not sure if that makes a difference. Here is the link to the video: https://www.youtube.com/watch?v=0aRjInmibSw&t=1055s THE TIMESTAMP FOR HIS CODE IS 6 min.
FILE NAME: Export.json
MY FILE LOCATION: C:\Users\Jordan\Downloads
MY CODE
import json
with open(r'C:/Users/Jordan/Downloads/Export.json','r') as f:
j=json.load(f)
print (j)
MY ERROR MESSAGE:
Traceback (most recent call last):
File "D:\Mixed Graphs\Blender json\3D Charts.blend\My Script", line 3, in <module>
OSError: [Errno 22] Invalid argument: '/C:/Users/Jordan/Downloads/Export'
Error: Python script failed, check the message in the system console
HIS CODE:
import json
with open('/Home/chris/downloads/tutorial1.json') as f:
json.load(f)
print (j)
Your problem seems to be that you're using "/"(slash) instead of ""(backslash) on Windows.
In addition you need to use two "\" as one backslash signals an escaping for the next character.
Fix therefore should be:
import json
with open(r'C:\\Users\\Jordan\\Downloads\\Export.json','r') as f:
j=json.load(f)
print (j)
I recently made a program using an external document with pickle. But when it tries to load the file with pickle, I got this error (the file is already existing but it also fails when the file in't existing):
python3.6 check-graph_amazon.py
a
b
g
URL to follow www.amazon.com
Product to follow Pool_table
h
i
[' www.amazon.com', ' Pool_table', []]
p
Traceback (most recent call last):
File "check-graph_amazon.py", line 17, in <module>
tab_simple = pickle.load(doc_simple)
io.UnsupportedOperation: read
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "check-graph_amazon.py", line 42, in <module>
pickle.dump(tab_simple, 'simple_data.dat')
TypeError: file must have a 'write' attribute
Here is the code :
import pickle5 as pickle
#import os
try:
print("a")
with open('simple_data.dat', 'rb') as doc_simple:
print("b")
tab_simple = pickle.load(doc_simple)
print("c")
print(tab_simple)
print("d")
URL = tab_simple[0]
produit_nom = tab_simple[1]
tous_jours = tab_simple[2]
print("f")
except :
print("g")
URL = str(input("URL to follow"))
produit_nom = str(input("Product to follow"))
with open('simple_data.dat', 'wb+') as doc_simple:
print("h")
#os.system('chmod +x simple_data.dat')
tab_simple = []
tab_simple.append(URL)
tab_simple.append(produit_nom)
tab_simple.append([])
print(tab_simple)
print("c'est le 2")
print("p")
pickle.dump(tab_simple, 'simple_data.dat')
print("q")
The prints are here to show which lines are executed. The os.system is here to allow writing on the file but the error is persisting.
I don't understand why it's said that the document doesn't have a write attribute because I opened it in writing mode. And I neither understand the first error where it can't load the file.
If it can help you the goal of this script is to initialise the program, with a try. It tries to open the document in reading mode in the try part and then set variables. If the document doesn't exist (because the program is lauched for the first time) it goes in the except part and create the document, before writing informations on it.
I hope you will have any clue, including changing the architecture of the code if you have a better way to make an initialisation for the 1st time the program is launched.
Thanks you in advance and sorry if the code isn't well formated, I'm a beginner with this website.
Quote from the docs for pickle.dump:
pickle.dumps(obj, protocol=None, *, fix_imports=True)
Write a pickled representation of obj to the open file object file. ...
...
The file argument must have a write() method that accepts a single bytes argument. It can thus be an on-disk file opened for binary writing, an io.BytesIO instance, or any other custom object that meets this interface.
So, you should pass to this function a file object, not a file name, like this:
with open("simple_data.dat", "wb"): as File:
pickle.dump(tab_simple, File)
Yeah, in your case the file has already been opened, so you should write to doc_simple.
When I 'print' some hex string, some interesting error information in python, I wonder why this error is caused.
Win10(I tried it on ubuntu, No ERROR),python 2.7
enc_hex = '''f982f01c'''
enc_ascii = enc_hex.decode('hex')
print(enc_ascii)
Traceback (most recent call last):
File ".\xxxx.py", line 7, in <module>
print(enc_ascii)
IOError: [Errno 2] No such file or directory
Well,in fact I want to know why "print" a special set of hex will cause file operation, other hex string will not error
Try using codecs.decode:
import codecs
enc_hex = '''f982f01c'''
enc_ascii = codecs.decode(enc_hex, 'hex')
print(enc_ascii)
Output:
b'\xf9\x82\xf0\x1c'
it seems like directory problems . in windows you have to use forward slash (/) while accessing the directory.similar was happened in my case then i use forward slash in windows then it works.
I have a very strange problem where I can't open a file from one of my larger scripts.
This problem is intermittent and I can't seem to understand the error.
I am getting this error:
IOError: [Errno 22] invalid mode ('w+') or filename: 'D:\\R4a\\2014_05\\R01359\\R01359_data_dwnhi.dat'
from this command in my script:
with open(os.path.normpath(os.path.join(sonpath,base+'_data_dwnhi.dat')), 'w+') as ff:
fp = np.memmap(ff, dtype='int16', mode='w+', shape=np.shape(tmp2))
when I use:
if os.path.exists(os.path.normpath(os.path.join(sonpath,base+'_data_dwnhi.dat')))== True:
print os.path.normpath(os.path.join(sonpath,base+'_data_dwnhi.dat')) + ' is a file'
it evaluates as True. Also when I run the open command by itself in ipython it sucessfully opens the file with:
open('D:\\R4a\\2014_05\\R01359\\R01359_data_dwnhi.dat', 'w+')
I am at a loss for words and think errno 22 error is misleading. As I stated earlier, the problem is intermittent and works on some files. Does anyone have an idea what I am doing wrong?
I am working on a windows 8 machine 64 bit and running python version 2.7.8 from an Anaconda 2.1.0 (64-bit) distribution.
Your opening it like a normal file, hence the error: IOError: [Errno 22] invalid mode. Do this instead:
with open(path, 'wb') as f:
pass
after some trial-errors, instruct np.memmap() to open a file with other than .__doc__ reported mode strings.
#------------------------------------------------------++++++++ TRY:
# ||||||||
# vvvvvvvv
|>>> MM = np.memmap( "temporary_DATA.memmap", mode = 'wNONSENSE+' )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27.anaconda\lib\site-packages\numpy\core\memmap.py", line 208, in __new__
(valid_filemodes + list(mode_equivalents.keys())))
ValueError: mode must be one of ['r', 'c', 'r+', 'w+', 'readwrite', 'write', 'readonly', 'copyonwrite']
# ^ ^ ^ ^ ^ ^ ^ ^
# | | | | | | | |
#---------------------------------+----+----+-----+-----+------------+--------+-----------+
finally this error Traceback has shown alternative strings, not listed in np.memmap.__doc__, which do work fine
with open( os.path.normpath( os.path.join( sonpath,
base + '_data_dwnhi.dat'
)
),
'w+'
) as ff:
fp = np.memmap( ff, mode = 'readwrite', # options listed in np Traceback
shape = np.shape( tmp2 ),
dtype = 'int16'
)
For hawkish pythoneers, the post intentionally uses non-PEP-8 source code formatting as it is authors experience that during a learning phase, code read-ability improves the focus on task solution and helps getting used to the underlying concepts rather than to spend efforts on formally adhering typography. Hope the principle of providing help is respected and the non-PEP-8 styling format is forgiven in the name of the ease of reading.