I have a script:
if (enviar_ftp(mounted_usb) >= 0): # ML: enviar_ftp()->enviar_ftp(ser)
# Se agrega la captura de schedule online
s = get_schedule_online(get_id())
log("Programa en servidor: {0}".format(s))
if (s != ""):
save_programa(s)
enviar_situacion(get_id(), get_programa(), get_free_space()[3], 0, 0, str(100-int(get_free_space()[4])), battery_status(voltaje), voltaje, 0, 0)
# ser_write("<txt>\n")
else:
log('enviar_ftp() failed') # ser_write("<txn>\n")
Works fine in python2 but in python3 I get:
Traceback (most recent call last):
File "/home/pi/main.py", line 511, in <module>
app_main()
File "/home/pi/main.py", line 499, in app_main
send_pics()
File "/home/pi/main.py", line 241, in send_pics
enviar_situacion(get_id(), get_programa(), get_free_space()[3], 0, 0, str(100-int(get_free_space()[4])), battery_status(voltaje), voltaje, 0, 0)
TypeError: 'NoneType' object is not subscriptable
Any ideas?
Expect the script to work!!
Related
How to resolve this error
Traceback (most recent call last):
File "C:\Users\sairaj\try.py", line 4, in <module>
parsedAddress = parser.runParser("The White House 1600 Pennsylvania Avenue NW, Washington, DC 20500, USA")
File "C:\Users\sairaj\anaconda3\Lib\site-packages\pypostalwin.py", line 58, in runParser
return outputStripper(result)
File "C:\Users\sairaj\anaconda3\Lib\site-packages\pypostalwin.py", line 20, in outputStripper
result = result.split('Result:\n\n')[1].split('\n\n> ')[0].replace('\n', '')
IndexError: list index out of range
I changed shell = True but still its not working
I'm working on a project, using openmodelica. I'm trying to simulate the system multiple times and i wrote a python script to automatize it. I also override parameters on each iteration of the simulation, but if i try to override an array i'll get this on console:
Traceback (most recent call last):
File "pythonScripts/testing.py", line 164, in <module>
startSimulation(5,2,1,4, noFault,flyZone[1])
File "pythonScripts/testing.py", line 118, in startSimulation
vars = omc.sendExpression("readSimulationResult(\"System_res.mat\",{time})")
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/__init__.py", line 779, in sendExpression
answer = OMTypedParser.parseString(result)
File "/home/francesco/.local/lib/python3.8/site-packages/OMPython/OMTypedParser.py", line 120, in parseString
res = omcGrammar.parseString(string)
File "/home/francesco/.local/lib/python3.8/site-packages/pyparsing/core.py", line 1143, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found '(' (at char 4), (line:1, col:5)
This is an example of how i did it:
def startSimulation(n, intr, miss, statObs, fault, flyZone):
with open("newValues.txt", 'wt') as f:
f.write("const.N="+str(n)+"\n")
f.write("const.nIntr="+str(intr)+"\n")
f.write("const.nRocket="+str(miss)+"\n")
f.write("const.nStatObs="+str(statObs)+"\n")
f.write("fault.transMatrix[4,4]="+str(fault)+"\n")
f.write("const.flyZone[3]="+flyZone+"\n")
f.flush()
os.fsync(f)
os.system("./System -overrideFile=newValues.txt >> LogOverride")
noFault = "[1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0; 1, 0, 0, 0]"
flyZone = ["{100,100,100}","{150,150,150}","{200,200,200}"]
startSimulation(5,2,1,4, noFault,flyZone[1])
Any suggestion?
OpenModelica will expand arrays into scalars when the C code is generated so you need to override each of the array elements separately in newValues.txt:
fault.transMatrix[1,1]=1
fault.transMatrix[1,2]=0
fault.transMatrix[1,3]=0
fault.transMatrix[1,4]=0
fault.transMatrix[2,1]=1
fault.transMatrix[2,2]=0
fault.transMatrix[2,3]=0
fault.transMatrix[2,4]=0
...
I have defined a new derived dimension with
[molar_energy] = [energy] / [substance]
However, if I do the following it complains:
>>> UR.get_compatible_units('[molar_energy]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 881, in get_compatible_units
equiv = self._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 2082, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 1835, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 891, in _get_compatible_units
return self._cache.dimensional_equivalents[src_dim]
KeyError: <UnitsContainer({'[length]': 2, '[mass]': 1, '[substance]': -1, '[time]': -2})
I saw that there is a conversion included in a context but I don't use it. What I am doing wrong?
Thanks for your help
PS: logged issue https://github.com/hgrecco/pint/issues/1418
Just leaving the solution here for anyone who faces this issue as well.
I just added a made-up unit and it worked
# Molar Energy
[molar_energy] = [energy] / [substance]
mol_en = J / mol
Hey I am using python script to create ".json" file and getting following error
Traceback (most recent call last):
File "ngs_rawdata_config_creator.py", line 104, in <module>
per_lib = parse_per_lib(pd.read_csv(args.per_lib_input, dtype=str))
File "ngs_rawdata_config_creator.py", line 32, in parse_per_lib
per_lib_dict['lib_paths'] = assign_libpaths(lib_basepaths)
File "ngs_rawdata_config_creator.py", line 53, in assign_libpaths
libpaths_dict[lib] = basepath_to_filepathsdict(path, "*.fastq.gz", ".*_L(\d+)_R(\d+).*\.fastq\.gz")
File "ngs_rawdata_config_creator.py", line 73, in basepath_to_filepathsdict
if rmatch.group(0) == basename:
AttributeError: 'NoneType' object has no attribute 'group
'
this is the part of the code
for fq in all_fastqs:
basename = os.path.basename(fq)
rmatch = re.match(capture_regex, basename)
if rmatch.group(0) == basename:
lane = rmatch.group(1)
read = rmatch.group(2)
readgroups[lane][read] = fq
If re.match doesn't get a match, it returns None. You need to check for that:
if rmatch and rmatch.group(0) == basename:
I have written a small python script to read data from a digital thermometer, and everything works just fine in my computer. however, i need to run this same script in other systems, but i keep getting a "[Errno 10060] Operation timed out" error.
in the second computer i can see the device, it's endpoints and everything, but it's when i try to read from it that i'm getting the error.
this is the code (i intentionally did not set the configuration for the device, as i'm trying to speed up the reading, and in my system it proved not to be necessary):
import usb.core
def get_temp(T):
# find our device
dev = usb.core.find(idVendor=0x04d9, idProduct=0xe000)
# was it found?
if dev is None:
raise ValueError('Device not found')
# poll the thermometer for current temperature
t = dev.read(0x83, 32) # gets 32 bytes from ENDPOINT address 0x83
so, in the computer where i wrote this, it works as expected, and it returns a nice 32-byte array. but in other systems, i got the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\usb\core.py", line 402, in read
return self.device.read(self, size_or_buffer, timeout)
File "C:\Python27\lib\site-packages\usb\core.py", line 988, in read
self.__get_timeout(timeout))
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 851, in
intr_read
timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 936, in
__read
_check(retval)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595, in
_check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 10060] Operation timed out
i tried also setting device configuration this time, but still same error.
any ideas on what i might be missing?
edit: this is my output log with PYUSB_DEBUG environment variable set to debug:
>>> dev.read(0x83,32)
2019-01-11 10:35:06,951 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>)
2019-01-11 10:35:06,953 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,954 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0)
2019-01-11 10:35:06,956 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_endpoint_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.claim_interface(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.intr_read(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>, 131, 0, array('B', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 1000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\usb\core.py", line 988, in read
self.__get_timeout(timeout))
File "C:\Python27\lib\site-packages\usb\_debug.py", line 60, in do_trace
return f(*args, **named_args)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 851, in intr_read
timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 936, in __read
_check(retval)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 10060] Operation timed out
>>>