Yep.  That seems fine.  Thanks.  

SQLAlchemy doesn't escape or quote the name.   I checked using

    inspection = inspect(Student)
    return [c_attr.key for c_attr in inspection.mapper.column_attrs]
On Monday, April 12, 2021 at 5:55:07 AM UTC-5 Richard Damon wrote:

> On 4/12/21 12:29 AM, Rob Rosenfeld wrote:
> > Hi All,
> >
> > I'm using SQLAlchemy to access a legacy MSSQL database.   I'm using
> > the autoload feature to load the schema from the database.
> >
> > In this example I'd like to read data out of the column named
> > "1st_period" in the database.   The following query shows the SQL I'd
> > need.  But trying to access a property named "1st_period" yields a
> > SyntaxError
> >
> > Thanks,
> > Rob
> >
> > SELECTTOP 10[1st_period] FROM Students;
> >
> > class Student(Model):
> > __table__ = Table("Students", metadata, autoload=True,
> > autoload_with=engine)
> >
> > @property
> > def first_period(self):
> > return self.1st_period
>
>
> Have you tried using getattr? That might work (if SQLAlchemy isn't doing
> something to quote the name to make a valid version.
>
> getattr(self, '1st_period') would be the equivalent of self.1st_period,
> but not have the name parsed by Python.
>
> -- 
> Richard Damon
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/7c1ba9f7-25c2-4cb2-b58c-4ba1c77c8c04n%40googlegroups.com.

Reply via email to