On 29May2024 01:14, Thomas Passin wrote:
Also, it's 2024 ... time to start using f-strings (because they are
more readable than str.format())
By which Thomas means stuff like this:
print(f'if block {name[index]} and index {index}')
Notice the leading "f'". Personally I wouldn't even go t
Your code is unreadable. The lines have all run together. And after
that, kindly explain what you want your code sample to do. "Process"
doesn't say much.
From what I can make out about what you are trying to do, you would do
better to index through your string with
for i, chr in enumerate
The format in this email is not of my making, should someone know, how to do
this so that it's a readable script do tell!
KMW
***
"When you pass through the waters, I will be with you: and when you pass
through the rivers, they will not sweep over
The following is my effort to understand how to process a string, letter, by
letter:
def myfunc(name): index = 0 howmax = len(name) # while (index <=
howmax): while (index < howmax): if (index % 2 == 0):
print('letter to upper = {}, index {}!'.format(name[index]
Most Python objects aren't serializable into JSON. Pydantic isn't
special in this sense.
What can you do about this? -- Well, if this is a one-of situation,
then, maybe just do it by hand?
If this is a recurring problem: json.dumps() takes a cls argument that
will be used to do the serialization.
Just getting started with pydantic. I have this example code:
class FinishReason(Enum):
stop = 'stop'
class Choice(BaseModel):
finish_reason: FinishReason = Field(...)
But I cannot serialize this:
json.dumps(Choice(finish_reason=FinishReason.stop).dict())
*** TypeError: Object of type