0

I am trying to use the strings in a list as the columns names in an sqllite database I am creating. I currently have the following code (using sqlalchemy):

db = create_engine('sqlite:///strings.db')
db.echo = False
metadata = MetaData(db)
lang_array = []
lang_array.append(Column("id", Integer, primary_key = True))
for lang in lang_keys:
    lang_array.append(Column(lang, String))

strings = Table("strings", metadata, lang_array)

Where lang_keys is a list of strings. Is it possible to pass a list in the Table method like above? I am getting the error AttributeError: 'list' object has no attribute 'schema. What am I doing wrong here?

1 Answer 1

1

You can use append_column() method:

strings = Table("strings", metadata)
for column in lang_array:
    strings.append_column(column)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.