-2

I have many google classroom invitations and I want to accept all of them through google app script using

Classroom.Invitations.accept("courseId");

but then I get no data back...

so I tried listing all my invitations using

Classroom.Invitations.list({"userId":"my_email"}); 

and still I get no data back...

I am very sure that my google classroom is full of unaccepted courses

jpf911
  • 117
  • 2
  • 9
  • 4
    The `strip()` method only removes from the start and end., not the middle – mousetail Jul 15 '22 at 12:57
  • 1
    [`strip`](https://docs.python.org/3/library/stdtypes.html#str.strip) returns a copy of the string with the leading and trailing characters removed. You're looking for [`replace`](https://docs.python.org/3/library/stdtypes.html#str.replace). – Matthias Jul 15 '22 at 12:58

4 Answers4

3

You need to consider, The strip() removes or truncates the given characters from the beginning and the end of the original string.

string= "this is my \n string"

print(string.replace('\n ', ''))

this is my string
I'mahdi
  • 23,382
  • 5
  • 22
  • 30
1

Python's strip removes characters from the left and right of strings, and any character supplied as a parameter is what will be removed from the left and right of the string. See here for more info https://www.programiz.com/python-programming/methods/string/strip

What you want to use is replace.

'string \n string'.replace('\n', '')

we are replacing every occurrence of \n with an empty string

1

The strip() function only targets leading/trailing characters. In your case, you want to cleanup whitespace inside the string. I suugest a regex replacement:

string = "this is my \n string"
output = re.sub(r'\s{2,}', ' ', string.strip())
print(output)  # this is my string
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

You can use replace to achieve your desired outcome.

string= "this is my \n string"

print(string.replace('\n', ''))

the output will be,

this is my  string
Tushar Patil
  • 748
  • 4
  • 13