Questions tagged [repr]

Python built-in function that returns a string from an arbitrary object. Abbreviation for "representation".

docs: https://docs.python.org/3/library/functions.html#repr

281 questions
-1
votes
1 answer

Need return to match what print is showing me

I need return to give what the last print line is giving me. At the bottom I have invoked class with values. Also, pointers to improve the code are welcome. class Building: def __init__(self, south, west, width_WE, width_NS, height=10): …
Abhicoding
  • 115
  • 1
  • 7
-1
votes
3 answers

Python unicode vs utf-8

I am building a string query (cypher query) to execute it against a database (Neo4J). I need to concatenate some strings but I am having trouble with encoding. I am trying to build a unicode string. # -*- coding: utf-8 -*- value = u"D'Santana…
p.magalhaes
  • 7,595
  • 10
  • 53
  • 108
-2
votes
1 answer

Why can __repr__ function use repr() in itself when defining a class?(Python)

class Link: def __repr__(self): if self.rest is not Link.empty: rest_repr = ', ' + repr(self.rest) else: rest_repr = '' return 'Link(' + repr(self.first) + rest_repr + ')' I wonder :Is the repr…
Half Dream
  • 11
  • 3
-2
votes
1 answer

I have a class with one required and two optional parameters, and a repr method which returns with one of the optional params, whichever is given

class MyClass(): def __init__(self, name, high=None, low=None): self.name = name if low: self.low = low elif high: self.high = high else: raise Error("Not found") def…
Pranava
  • 15
  • 4
-2
votes
3 answers

Different implementations of repr

So I have this class with the repr method implemented import reprlib class Test: def __init__(self, aList): self.my_list = [c for c in aList] def __repr__(self): # return " ".join((str(i) for i in self.my_list)) # …
MAA
  • 1,294
  • 3
  • 18
  • 34
-2
votes
2 answers

'object' in <__main__.Foo object at 0x10f43b7b8>

Suppose a class: class Foo(object): pass Make an instance: foo = Foo() Test them in interactive mode: In [80]: print(Foo) Good hint, class 'Foo' in first_class module __main__, However: In [81]: print(foo) <__main__.Foo…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
-2
votes
1 answer

Preserve the formatting(whitespace & newlines) of the response received from executing a command over ssh

I am writing an application in Python, I am using pexpect ( more specifically the pxssh functionality) to execute a series of commands on a Cisco Router. I want to store the output returned to a variable intact with the whitespaces and the newlines.…
-2
votes
1 answer

Python how to use the __str__ code for the __repr__?

I've stated programming in Phyton just few days ago, so I'm sorry if the question is quite easy. I've written this code: >>> class Polynomial: def __init__(self, coeff): self.coeff=coeff def __repr_(self): …
-2
votes
6 answers

Python print number range on multiple lines

I'm just trying to do some looping functions in Python, however I am pretty much stuck here. I don't know if it should be a nested or simultaneous loop, and if so, how to use it probably. Python is telling me (ValueError: too many values to…
Emil Elkjær
  • 685
  • 1
  • 9
  • 31
-3
votes
2 answers

Why am I getting a SyntaxError when instantiating a __repr__method

I receive the following error when I instantiate a class with a repr method I have. When I remove the repr it works fine: repr removed class Wide(): def __init__(self, XfromLeftEdge = 141.0, YfromTopEdge = 300.0, Width = 1551.0, Height = 800.0…
Windy71
  • 851
  • 1
  • 9
  • 30
-4
votes
1 answer

when I use the repr function it is not working

I am trying to remove the ' ' in my list by using the repr function but it is not removing the ' ' code: output: output input
jarey249
  • 1
  • 1
1 2 3
18
19