Why is this simple Python script failing? Python 2.6.6 [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Here's the script
#!/usr/bin/python
class LEG(Structure):
_fields_ = [("distance_sm", c_float), ("distance_nm", c_float)]
Here's what I get when I run it.
Traceback (most recent call last):
File "./test.py", line 3, in <module>
class LEG(Structure):
NameError: name 'Structure' is not defined
Yes, brand new to python, thanks for your help

It looks like you're trying to use the Structure type from the ctypes module. You need to import that, as well as c_float and anything else you use from that module:
from ctypes import Structure, c_float

Related

Why am I getting a invalid syntax on this call method? Python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to make a script that can delete a file with Python. When I moved the file to my startup directory with my script, a lot of the code was changed, not by me. I've just assumed this was normal and continued trying to make it delete a file on startup. I later realized it wasn't working because one of the call methods kept getting an invalid syntax. Here's my code.
Python Version: 3.8.7
Error message is :
invalid syntax (<unknown>, line 7)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(os), STORE_NAME(os)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(shutil), STORE_NAME(shutil)
source = 'C:\\Users\\me\\OneDrive\\Desktop\\startup.py'
destination = 'C:\\Users\\me\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
LOAD_NAME(shutil), LOAD_METHOD(move), LOAD_NAME(source), LOAD_NAME(destination), CALL_METHOD[2], STORE_NAME(new_path)
print(new_path)
LOAD_NAME(os), LOAD_METHOD(remove), LOAD_CONST('C:/Users/me/OneDrive/Desktop/delete.txt'), CALL_METHOD[1], POP_TOP
print('File Removed!'), return None
From the code, it's difficult to understand what you are trying to do. If you want to delete a file, you can use the os module in python. For example:
import os
os.remove("/some/file/path/to/remove.txt")

AttributeError: module 'django.db.models' has no attribute 'DataField' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
i tried running my server then i got this updated_at=models.DataField(auto_now_add=True) AttributeError: module 'django.db.models' has no attribute 'DataField'
Based on the line of the error, here is the code exactly where the error was detected.
id=models.AutoField(primary_key=True)
name=models.CharField(max_length=225)
email=models.CharField(max_length=224)
password=models.CharField(max_length=225)
created_at=models.DateField(auto_now_add=True)
updated_at=models.DataField(auto_now_add=True)
objects=models.Manaager()
Kindly help me as i am new to python
You wrote DataField, instead it should DateField.
Also Manaager should be Manager.
Your code should look like this:
id=models.AutoField(primary_key=True)
name=models.CharField(max_length=225)
email=models.CharField(max_length=224)
password=models.CharField(max_length=225)
created_at=models.DateField(auto_now_add=True)
updated_at=models.DataField(auto_now_add=True)
objects=models.Manager()

Attribute Error on python 3x [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am working on Object detection with tensorflow api. I take codes on githup and try to debug and I face to face that error.
File "<ipython-input-10-7adfcc2a8173>", line 3, in <module>
with detection_graph.as_defult():
AttributeError: 'Graph' object has no attribute 'as_defult'
No problem with my camera. I aldready installed which necessary every module
PLSS help me
thank you
Without your code I cannot be entirely certain it is the only issue, but I think you are getting the error because of a misspelling. It should be as_default instead of as_defult. Use detection_graph.as_default() instead.

Numpy - module has no attribute 'arrange' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Seems like an incredibly basic error, I've tried uninstalling and reinstalling the latest version of Numpy (1.9) and that didn't seem to solve my issue. I am getting the following error when trying to use the arrange function:
Traceback (most recent call last):
File "names.py", line 37, in <module>
top1000.index = np.arrange(len(top1000))
AttributeError: 'module' object has no attribute 'arrange'
Printing the version confirms that it is indeed 1.9. I've not been able to come across anyone else reporting this specific issue. I've also tried this on two separate Macs and still get the same exact error.
import numpy as np
import pandas as pd
print np.__version__
grouped = names.groupby(['year', 'sex'])
top1000 = grouped.apply(get_top1000)
top1000.index = np.arrange(len(top1000))
You should try numpy.arange() instead, if that is what you meant?

import all functions vs. import specific function [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
In Python,
import shutil, os
allows me to call os.environ, os.path.exists(folder), os.listdir(pool), shutil.rmtree(folder) and shutil.copyree(). It seems that I call any function, defined in those modules. Nevertheless, I cannot call ctime() once I have imported import time. I must import ctime explicitly, by
from time import ctime
Why is such inconsistency? I find it difficult to program in such unpredictability.
from time import ctime allows to call ctime() directly, without time.ctime() prefix. It is me, who was inconsistent comparing fully qualified names os.listdir() with ctime() alone.

Categories