473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Error message...object cant find attribute

Expand|Select|Wrap|Line Numbers
  1. class Encrypt(object):
  2.  #The worst object ever created
  3.     def __init__(self,alphabet):
  4.         self.alphabet = alphabet
  5.         self.trans = self.maketrans()
  6.         self.count = -1
  7.         self.translist = []
  8.  
  9.     def maketrans(self):
  10.         x = (random.randrange(0,len(self.alphabet)))
  11.         if(self.count == len(self.alphabet)):
  12.             return(self.translist)
  13.         elif(x in self.translist):
  14.             x = input("enter a number, bitch")
  15.             self.count += 1
  16.             self.translist.append(x)
  17.             return(maketrans(self))
  18.         else:
  19.             self.count += 1
  20.             self.translist.append(x)
  21.             return(maketrans(self))
  22.  
  23. alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
  24. encrypt1 = Encrypt(alphabet)
  25. print(encrypt.trans)
----------------------------

I get this error

-----------------------

Traceback (most recent call last):
File "C:\Users\iStrawser\UD\CISC 106\Pythons\lab7.py", line 76, in <module>
encrypt1 = Encrypt(alphabet)
File "C:\Users\iStrawser\UD\CISC 106\Pythons\lab7.py", line 56, in __init__
self.trans = self.maketrans()
File "C:\Users\iStrawser\UD\CISC 106\Pythons\lab7.py", line 62, in maketrans
self.count += 1
AttributeError: 'Encrypt' object has no attribute 'count'

--------------------
Why can't I get a list of numbers that encode the alphabet? I'm not sure I know what to do to make a recursive function in a class.
Oct 31 '11 #1
4 2234
dwblas
626 Expert 512MB
That means that it is not a member of the class, which is usually an indentation problem, but there is no way to tell since you did not hit the code tag (# at the top of the reply box) and post your code between the [code] and [/code] tags.
I'm not sure I know what to do to make a recursive function in a class
You would not use recursion here, just a loop
for letter in alphabet:
Look at the problem again and state it more clearly.
Oct 31 '11 #2
#
Expand|Select|Wrap|Line Numbers
  1. class Encrypt(object):
  2.  #The worst object ever created
  3.     def __init__(self,alphabet):
  4.         self.alphabet = alphabet
  5.         self.trans = self.maketrans()
  6.  
  7.     def maketrans(self,x,translist):
  8.         r = (random.randrange(0,len(self.alphabet)))
  9.         if(x == len(self.alphabet)):
  10.             return(translist)
  11.         elif(r in translist):
  12.             r = input("enter a number, bitch")
  13.             translist.append(x)
  14.             return(self.maketrans(self,x + 1,translist))
  15.         else:
  16.             self.translist.append(x)
  17.             return(maketrans(self,x + 1,translist))
  18.  
  19. alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
  20. encrypt1 = Encrypt(alphabet,0,[])
  21. print(encrypt1.maketrans)
  22.  
Oct 31 '11 #3
dwblas
626 Expert 512MB
My mistake, self.count is declared after self.maketrans() is called, which uses self.count, so just reverse these two statements in __init__.
Expand|Select|Wrap|Line Numbers
  1.         self.trans = self.maketrans()
  2.         self.count = -1
Oh well, you learned how to use code tags at least.
Oct 31 '11 #4
bvdet
2,851 Expert Mod 2GB
I saw a few more problems:

To call method maketrans: self.maketrans(x,translist)

The number of arguments in Encrypt._init__() do not match the call encrypt1 = Encrypt(alphabet,0,[])

'Encrypt' object has no attribute 'translist'
Oct 31 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
3
by: Evangelista Sami | last post by:
hello i have this strange error message that i dont understand : _search.c: In function `_depth_search': _search.c:218: unable to find a register to spill in class `AREG' _search.c:218: this...
1
by: JP Lacasse | last post by:
I translate a web application from ASP to ASP.NET and I keep getting the following error: Could not find installable ISA I used the same ConnectString ("DBQ=" &...
3
by: Kenneth P | last post by:
Hi, Something has happened with one of my vs.net2003 projects. I can't start it, it says "Visual Studio .Net cannot create or open the application because the current user account is not a...
1
by: Skeptical | last post by:
Greetings, This question is related to Microsoft Reporting Services Web service. I tried asking it in RS groups but no one seems to be knowledgeable enough to answer, so I wanted to try my...
5
by: johnny | last post by:
I am getting the following errors: File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in _send_output self.send(msg) File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in...
1
by: brainstormer | last post by:
I'm new to this site and seeking help with an Error message. I have a program in HP called Image Zone. A few weeks ago all my photos disappeared and I got this error message..."Object reference not...
0
by: urveshv | last post by:
Hello, I got a problem to view a page and getting above error. The strange thig is I am geeting this error in one login. When I am login with administrator creditentails it allows me. the codes...
4
by: Montezuma's Daughter | last post by:
Hi all it is my first application. I wrote a class libraray with functions and a simple class with form, textbox, buttons and a label. I added reference to the second class so I would read the...
1
by: Jim Rockett | last post by:
"if(CURVE(RESD) < 0.001 ? 0.001 : CURVE(RESD))"
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.