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 7170781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:16:52+00:00 2026-05-28T15:16:52+00:00

I am trying to make my python2.x-Code compatible with both 2.7 and 3.x. Currently

  • 0

I am trying to make my python2.x-Code compatible with both 2.7 and 3.x. Currently I am stuck at some Code in Pmw.py (from python megawidgets). Have a a look at the first three entries of this dictionary:

_standardValidators = {
'numeric'      : (numericvalidator,      string.atol),
'integer'      : (integervalidator,      string.atol),
'hexadecimal'  : (hexadecimalvalidator,  lambda s: string.atol(s, 16)),
'real'         : (realvalidator,         Pmw.stringtoreal),
'alphabetic'   : (alphabeticvalidator,   len),
'alphanumeric' : (alphanumericvalidator, len),
'time'         : (timevalidator,         Pmw.timestringtoseconds),
'date'         : (datevalidator,         Pmw.datestringtojdn),
}

The first two entries contain “string.atol”. My questions are:

  1. In the python docs atol is introduced as a function ( string.atol(s[, base]) ) , so there should be parentheses, which are missing here. So how is this syntax to be understood?

  2. In python 3.2 this code raises the error:

    'numeric'      : (numericvalidator,      string.atol),
    AttributeError: 'module' object has no attribute 'atol'
    

    I already tried replacing the three occurences of “atol” with long, like suggested in the python docs, but that just raised the error:

    'numeric'      : (numericvalidator,      string.long),
    AttributeError: 'module' object has no attribute 'long'
    

    As I don’t even understand the syntax, I’m quite helpless about what to try next. How is this code to be fixed, so that it works both in python 2.7 and 3.x?

Hope you can help me on that one.

  • 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-28T15:16:53+00:00Added an answer on May 28, 2026 at 3:16 pm

    1: string.atol is the function itself: functions are first-class objects in python. The parentheses are only used for a call.

    >>> import string
    >>> string.atol
    <function atol at 0x00B29AB0>
    >>> string.atol("aab2", 16)
    43698L
    

    2: I think you must have misread. long doesn’t live in string, but there isn’t a long in Python 3 anyway. That’s a relic of when Python distinguished between small integers and long integers in ways that could be seen from userspace. (That’s what the “L” on the end of 43698L above means.)

    Simply use int, i.e.

    'numeric': (numericvalidator, int),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to refactor some python code and I'm stuck with an import error
I have some code that I am trying to make it play nicely with
I'm trying to make a python binding for the this library: http://code.google.com/p/hosterslib/ . I'm
I have been trying to make a case for using Python at my work.
I'm trying to create a python program (using pyUNO ) to make some changes
I'm trying to make an array out of a text file My django/python code
I have been trying to make a cash register like code, where the user
I'm trying to figure whats wrong with some autogenerated (with Pyste) boost::python code, but
I am trying to make some python scripts on google appspot. I am just
I am trying to speed up some python code with cython, and I'm making

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.