#Python help

69 messages · Page 1 of 1 (latest)

whole parrotBOT
#

@dusk hollow

palos4290 Uploaded Some Code

hi, I am pretty new to programming, and i download a python code from yt for an object counter with the camera, everything is working fine, but its suppose to send all the information to excell and i cant make it work, here is the code and the error i have: File "C:\Program Files\Python311\counting_excel.py", line 29, in <module>
ws.append(("datetime","total_output","minute","ppm"))
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

Uploaded these files to a Gist
dusk hollow
#

https://www.youtube.com/watch?v=ntVk5gKXVKc this is how its supposed to work

Requirement:

  1. Install numpy
    $ pip install numpy
  2. Install opencv
    $ pip install opencv-python
  3. Install pyyaml
    $ pip install pyyaml
  4. Install openpyxl
    $ pip install openpyxl
    Additional installation
    CSV
    $ pip install python-csv

Link code: https://drive.google.com/file/d/16LIW-lvtknD6OJkR8Zlom1fx5sKxYbgP/view?usp=sharing

If you find thi...

▶ Play video
mossy vector
#

Check your ws object before you append it

#

See if it's correct

dusk hollow
mossy vector
dusk hollow
#

But does this seems correct?

mossy vector
#

Print ws before the error

#

See what you get

dusk hollow
#

how?

#

sorry i litteraly started yesterday xd

mossy vector
#

print(ws)??

dusk hollow
mossy vector
#

Yeah

dusk hollow
#

i got this and i already got this with some other tests

mossy vector
#

Use r"..." for your file path

#

As in, put an r Infront of the string

dusk hollow
#

3 dots?

#

in the original it had 2

mossy vector
#

Nah don't do the dots

#

Just add r in front of the path

dusk hollow
#

File "C:\Program Files\Python311\counting_excel.py", line 29, in <module>
ws.append(("datetime","total_output","minute","ppm"))
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

#

im back at this same problem

#

i found this on google

dusk hollow
# mossy vector What's above it?

C:\Users\Palos>counting_excel.py
None
Traceback (most recent call last):
File "C:\Program Files\Python311\counting_excel.py", line 28, in <module>
ws.append(("datetime","total_output","minute","ppm"))
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

mossy vector
#

You see how there's None

dusk hollow
#

yes

mossy vector
#

That's why you're getting that error

#

Maybe try print out wb instead

#

and see what comes up

dusk hollow
#

so instead of print (ws) print(wb)

mossy vector
#

yeah

#

Try that

#

Cause either your workbook is invalid, or your active worksheet is invalid

dusk hollow
#

<openpyxl.workbook.workbook.Workbook object at 0x00000198D2351010>
Traceback (most recent call last):
File "C:\Program Files\Python311\counting_excel.py", line 28, in <module>
ws.append(("datetime","total_output","minute","ppm"))
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

mossy vector
#

Seems like a valid workbook

#

But I'm not sure anymore tbh

#

I've never used openpyxl

dusk hollow
#

i appreciate it man

#

at least its a different error finally xd

mossy vector
#

wb.active = wb[sheet_name]

#

You could try this

#

If you know the sheet name

dusk hollow
#

its Sheet1

#

but it says its not defined

mossy vector
#

Does it?

dusk hollow
# mossy vector Does it?

Traceback (most recent call last):
File "C:\Program Files\Python311\counting_excel.py", line 26, in <module>
ws = wb.active = wb[Hoja1]
^^^^^
NameError: name 'Hoja1' is not defined

mossy vector
#

nonono

dusk hollow
#

File "C:\Program Files\Python311\counting_excel.py", line 26, in <module>
wb.active = wb[Hoja1]
^^^^^
NameError: name 'Hoja1' is not defined

#

i tried this two

#

too

mossy vector
#

wb.active = wb["Hoja1"]

dusk hollow
#

Traceback (most recent call last):
File "C:\Program Files\Python311\counting_excel.py", line 26, in <module>
wb.active = wb["Hoja1"]
~~^^^^^^^^^
File "C:\Users\Palos\AppData\Roaming\Python\Python311\site-packages\openpyxl\workbook\workbook.py", line 287, in getitem
raise KeyError("Worksheet {0} does not exist.".format(key))
KeyError: 'Worksheet Hoja1 does not exist.'

#

this is how the guy in the video had it

#

And before he opens the excel it looks like this

dusk hollow
mossy vector
#

Does it work?

dusk hollow
mossy vector
#

@dusk hollow why not just use a csv file instead

dusk hollow
dusk hollow
#

How woulf that work?

mossy vector
dusk hollow