Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with namespaces when concepts begin with a numeral. #2631

Open
Nasreddine opened this issue Oct 31, 2023 · 2 comments
Open

Issue with namespaces when concepts begin with a numeral. #2631

Nasreddine opened this issue Oct 31, 2023 · 2 comments

Comments

@Nasreddine
Copy link

Hi,

I have defined Eurovoc namespace where some concepts begin with a digit. Python flags this as a syntax error.
Is there a solution to this problem?

from rdflib import Namespace, URIRef
eurovoc = Namespace("http://eurovoc.europa.eu/")

print(eurovoc.1005)

print(eurovoc.1005)
             ^
SyntaxError: invalid syntax
@gvozdetsky
Copy link

gvozdetsky commented Nov 7, 2023

@Nasreddine class Namespace accepts only string as name, see

  def __getattr__(self, name: str) -> URIRef:
      if name.startswith("__"):  # ignore any special Python names!
          raise AttributeError
      return self.term(name)

you can write:

from rdflib import Namespace

eurovoc = Namespace("http://eurovoc.europa.eu/")
concept = getattr(eurovoc, '1005')
print(concept)

@niklasl
Copy link
Member

niklasl commented Nov 7, 2023

The attribute access is a dynamic convenience (and within the bonds of python syntax). Item access (like with dictionaries) always works. So (preferably) you do:

print(eurovoc['1005'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants