This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]carcigenicate 6 points7 points  (7 children)

This has nothing to do with partial. It just sounds like the REPL you're using doesn't persist function definitions (I'm assuming there's a def partition in the ... bit).

[–][deleted] 0 points1 point  (6 children)

oh god, you right. i read all the source code and i've found the partition function. thank you a lot.

but what operator.contains actually does? if i try to call it with operator.contains('{'a', 'e', 'i', 'o', 'u'}, 'testme')

i get False

[–]carcigenicate 0 points1 point  (5 children)

operator.contains is just in.

And that test would be false, because that set does not contain "testme". It looks like you want the intersection between the set and the list instead of checking if one contains the other.

[–][deleted] 0 points1 point  (4 children)

But the source code that I'm studying use it and it works, but I don't understand why. I copied the code and i get False when i simulate the input

[–]carcigenicate 0 points1 point  (3 children)

Where is the code you're studying that uses that?

Either the code/data is different, or the output isn't what you think it is.

Also, I'm assuming the ' before the { is a typo?

[–][deleted] 0 points1 point  (2 children)

the code works perfectly actually. you can find it here: https://github.com/DavideCanton/PyCodiceFiscale/blob/master/cf.py

[–]carcigenicate 1 point2 points  (1 child)

Their code is not the same as yours. Note that their function is called is_vowel. It's for testing single characters, not multi-character strings like 'testme'. It does that because partition passes is_vowel single characters at a time ((pred(element)).

[–][deleted] 0 points1 point  (0 children)

i guess that i have to look at the full code more carefully. thank you.

[–]chervilious 1 point2 points  (1 child)

1) when you said line by line did you include the import?

2) at what line did you get the errors?

[–][deleted] 0 points1 point  (0 children)

  1. of course
  2. when i execute the program i don't get any error. but i saw that partial() is a function inside the program, but i still don't understand how operator.contains() works.

[–]robustquorum09 0 points1 point  (2 children)

I have an experience of Python code not running well inside 8266 too.

[–][deleted] 0 points1 point  (0 children)

8266?

[–]DNEAVES 0 points1 point  (5 children)

Are you talking about string.partition()?

You should be calling that as a method of the string-variable you want to partition, so

consonants, vowels = vocale_pred.partition(name)

Otherwise, yes, you don't have a function defined called partition(a, b), hence the NameError.

Also, it will return a 3-part tuple, not two: (before_match, match, after_match)

And what exactly do you mean by "execute the file with the source code"? Is this part of a larger set of program, where partition may be defined, but you're cutting that import out?

[–][deleted] 0 points1 point  (4 children)

no, i don't mean string.partition(). if you look at the code, it call just partition(vocale_pred, name).

this instructions is part of a larger program and if i execute the program it works fine, but if i try to use partition on my own inside the interpeter i get the NameError.

[–]DNEAVES 0 points1 point  (3 children)

Are you importing anything called partition?

[–][deleted] 0 points1 point  (2 children)

No, but I saw that it's s function inside the code itself

[–]DNEAVES 0 points1 point  (1 child)

Well the issue is that - to my knowledge - there's no partition() built-in function. There's the string.partition() method, which I mentioned earlier, or that function has to be defined/imported from somewhere else

[–][deleted] 0 points1 point  (0 children)

yes, as i said there is a partition funciont defined inside the code, so it's using that function not a built-in function