Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7567733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:44:20+00:00 2026-05-30T14:44:20+00:00

I’m rather new to Python. Lately I was looking into the python’s concept of

  • 0

I’m rather new to Python. Lately I was looking into the python’s concept of classes. Well, for a couple of scripts I wrote I thought it would be handy to define a class which puts together a SQL-statement (in ArcGis dialect). Nothing fancy really. Here is what I came up with. I’m asking two things: first, general flaws? Suggestions for improvement? Secondly, I’m a little stuck with the code of the last function def constructor. Actually I want to return the tuple from the dictionary and not a list. But the list comprehension is nice. So what about a generator? I can’t figure exactly out how to do that…

class ArcSql:
    type_book = {'str':("'","'"), 'int':("", "")}
    format_book = dict(shp=("'","'"), GDB=("[","]"))

    def __init__(self,colom_name, values_list, value_type = 'str', arc_format ='shp'):
        self.colom = colom_name
        self.values = values_list
        self.valtype = self.constructor(type_book, value_type)
        self.aformat = self.constructor(format_book, arc_format)
        self.colom_formated = str(self.aformat[0][0]) + self.colom + str(self.aformat[0][1])

    def statement(self):
        temp_state = []
        connector = "'OR' "
        count_values = len(self.values)
        if count_values == 0:
            return("error, not enough values...")
        else:
            for v in self.values:
                x = self.colom_formated + " = " + str(self.valtype[0][0]) + v + str(self.valtype[0][1]) + ' ' + connector
                temp_state.append(str(x))
        state = "".join(temp_state)[:-5]              
        return(str(state))

    def constructor(self, book, book_key):
        return([v for k,v in book.iteritems() if k==book_key])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:44:21+00:00Added an answer on May 30, 2026 at 2:44 pm

    Your first question should be better asked in the codereview site.

    Regarding your second question, you could use a generator as follows:

    def constructor(self, book, book_key):
        for k, v in book.iteritems():
            if k==book_Key:
                yield v
    
    ...
    
    for value in obj.constructor(book ,book_key):
        # Do whatever you need with value
    

    Anyway, my understanding is that you’re going to get only one result from the list comprehension, in such a case:

    def constructor(self, book, book_key):
        return next(v for k, v in book.iteritems() if k==book_key, None)
    
    ...
    
    value = obj.constructor(book ,book_key)
    if value is not None:
        # Do whatever you need with value
    

    Where next is a built-in to return the next value of an iterator or the default value passed (None in this case) if the iterator is exhausted (if no default value is passed, an exception will be raised in that case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.