Strange random error

import string
import random

def id_generator(size=8, chars=string.ascii_uppercase + string.digits):
return ‘’.join(random.choice(chars) for i in range(size))

quot_id = id_generator()
print (quot_id)

in IDLE 3.4 the above code runs fine: it gives me the result I want

however, that same code in anvil form gives me an error:
TypeError: start must be a integer at [find_price, line 18]

class find_price(find_priceTemplate):
def init(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
quot_id = self.id_generator()
print (quot_id)

def id_generator(size=8, chars=string.ascii_uppercase + string.digits):
return ‘’.join(random.choice(chars) for i in range(size)) # this is line 18

I can’t figure out what is wrong
please advise

thank you so much

Hi there,

To help others more easily read your code please format code by wrapping it in backticks with the word Python.

For example,

```python

print('this will be syntax highlighted')

```
1 Like

I think this is because you have missed “self” as the first argument to your “id_generator” method and so the form instance is being passed as your size argument.

2 Likes

thank you everyone for your reply
as i then realized that i need to move the value of quot_id from one form to another, i moved the code to Module and it works flawlessly, albeit not as a function

size=8
chars=string.ascii_uppercase + string.digits
quot_id = ''.join(random.choice(chars) for i in range(size))

thanks

sid