#๐Ÿ”’ I need help with camelcase

82 messages ยท Page 1 of 1 (latest)

crystal basinBOT
#

@final trench

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lucid berry
#

Have you already installed the module?

vast vapor
#

!pip camelcase

crystal basinBOT
#

Converts a string to Camel Case

Released on <t:1421059230:D>.

vast vapor
#

If you're facing difficulty installing it using your terminal, you can install it manually from here.

young finch
#

write your own version ๐Ÿ˜Ž

severe spindle
#

last release 2015. no chance, probably

young finch
#

!e

def camel_case(s: str) -> str:
      first, *rest = s.split("_")
      if not first: # s beings with '_'
        first, *rest = rest
      return first.lower() + "".join(word.title() for word in rest)

print(camel_case("_what_are_you_doing123"))
severe spindle
#

missing *

crystal basinBOT
#

@young finch :white_check_mark: Your 3.12 eval job has completed with return code 0.

whatAreYouDoing123
young finch
young finch
final trench
#

yes I think I installed it in the terminal typing , pip install camelcase

young finch
#

!e

def camel_case(s: str) -> str:
      prefix = ""
      first, *rest = s.split("_")
      if not first: # s beings with '_'
        prefix = "_"
        first, *rest = rest
      return prefix + first.lower() + "".join(word.title() for word in rest)

print(camel_case("_what_are_you_doing123"))
crystal basinBOT
#

@young finch :white_check_mark: Your 3.12 eval job has completed with return code 0.

_whatAreYouDoing123
young finch
#

tada

final trench
#

import camelcase

ModuleNotFoundError: No module named 'camelcase'

young finch
final trench
#

G1:~$ pip install camelcase
Requirement already satisfied: camelcase in ./anaconda3/lib/python3.11/site-packages (0.2)

young finch
#

oh it's unix

severe spindle
#

you don't need to install anything just for converting a string to camelcase

young finch
#

do you have multiple versions installed?

#

but yeah like... why do you need to install this library

#

I've shown that a function can be easily constructed, as I have done in 5 mins or so

final trench
#

Its a exercise from school

hazy cove
#

'_what_are_you_doing123'.title().replace('_', '')

final trench
#

1:~$ py -0
Kommandot "py" hittades inte, men kan installeras med:
sudo apt install pythonpy

#

should I install that ?

#

sorry its in swedish ..

young finch
crystal basinBOT
#

@young finch :white_check_mark: Your 3.12 eval job has completed with return code 0.

WhatAreYouDoing123
young finch
#

did not know that title would make stuff capitalized after underscores

#

very cool

#

but still that's not correct

hazy cove
#

pythonwhat is the desired output then

severe spindle
young finch
#

because the first letter should be lowercase and the underscore at the beginning should stay

hazy cove
#

oh

young finch
#

hmm also an underscore at the end should be there ๐Ÿค”

hazy cove
#

what underscore at the end

final trench
#

this was the excercise

import camelcase

c = camelcase.CamelCase()

txt = "hello world"

print(c.hump(txt))

young finch
#

"next_" should stay as "next_"

final trench
#

output

ModuleNotFoundError: No module named 'camelcase'

#

So how do I solve this ?

young finch
#

my guess is that you have multiple versions installed on your computer

#

try pip3 for the install perhaps

final trench
#

1:~$ pip3 install camelcase
Requirement already satisfied: camelcase in ./anaconda3/lib/python3.11/site-packages (0.2)

young finch
#

so then it's an issue in how you are running your file

#

which means you definitely have more than on version of python present

severe spindle
#

how are you running the python file? what command are you using?

final trench
#

ok how do I remove or delete

#

it was someone that told me to install it

#

when I already had it

#

hmm didnt know it could be a problem with linux if you try do double isntall that it can become a error

#

why does it allow that it to be double installed ?

young finch
#

it's not an error, you are just installing and running different versions

severe spindle
#

again: what command are you using to run your script?

final trench
#

didnt know of it in windows or mac

#

Im your spyder

#

but I dont understand this, when trying install , can I only do it in terminal or can I do it in spyder aswerll ? Because Ive been trying on both

#

Im trying to understand this Im still new

severe spindle
#

spyder and pip seem to be using different installed pythons

#

pip installs in anaconda, and spyder probably uses something else

#

I sadly don't know anything about spyder

#

in spyder you can try to use at the top of your python file:

import sys
print(sys.executable)
final trench
#

ok, maybe someone that understands spyder can help me then

#

thanks anyway

severe spindle
#

that should show the exact path to the python you're using

final trench
#

/usr/bin/python3

severe spindle
#

okay, that's a global python.. not sure you can easily install with pip using that... hmmm

#
/usr/bin/python3 -m pip --user camelcase
#

you might have to potentially create a venv (which I recommend anyway) .. but no idea how to tell spyder to use a specific python

final trench
#

NameError: name 'usr' is not defined

severe spindle
#

That command goes to the command line / terminal. Not the python terminal

final trench
strange jetty
young finch
strange jetty
#

thanks

young finch
strange jetty
#

yea, i can def do that if i us it

crystal basinBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.