I have some issue putting variable into the path [duplicate]










-2
















This question already has an answer here:



  • How do I put a variable inside a String in Python?

    7 answers



it 's possible to put a variable into the path in python/linux



for example :



>>>counter = 0;

>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))


I have syntax error when i do that.










share|improve this question















marked as duplicate by Daniel Roseman, usr2564301, tripleee linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 15:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • The documentation might be helpful here

    – DavidG
    Nov 12 '18 at 9:59












  • @Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

    – Adam Mitchell
    Nov 12 '18 at 10:59















-2
















This question already has an answer here:



  • How do I put a variable inside a String in Python?

    7 answers



it 's possible to put a variable into the path in python/linux



for example :



>>>counter = 0;

>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))


I have syntax error when i do that.










share|improve this question















marked as duplicate by Daniel Roseman, usr2564301, tripleee linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 15:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • The documentation might be helpful here

    – DavidG
    Nov 12 '18 at 9:59












  • @Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

    – Adam Mitchell
    Nov 12 '18 at 10:59













-2












-2








-2









This question already has an answer here:



  • How do I put a variable inside a String in Python?

    7 answers



it 's possible to put a variable into the path in python/linux



for example :



>>>counter = 0;

>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))


I have syntax error when i do that.










share|improve this question

















This question already has an answer here:



  • How do I put a variable inside a String in Python?

    7 answers



it 's possible to put a variable into the path in python/linux



for example :



>>>counter = 0;

>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))


I have syntax error when i do that.





This question already has an answer here:



  • How do I put a variable inside a String in Python?

    7 answers







python linux variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 10:29









betontalpfa

8451023




8451023










asked Nov 12 '18 at 9:56









Castelo Castelo

11




11




marked as duplicate by Daniel Roseman, usr2564301, tripleee linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 15:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Daniel Roseman, usr2564301, tripleee linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 15:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • The documentation might be helpful here

    – DavidG
    Nov 12 '18 at 9:59












  • @Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

    – Adam Mitchell
    Nov 12 '18 at 10:59

















  • The documentation might be helpful here

    – DavidG
    Nov 12 '18 at 9:59












  • @Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

    – Adam Mitchell
    Nov 12 '18 at 10:59
















The documentation might be helpful here

– DavidG
Nov 12 '18 at 9:59






The documentation might be helpful here

– DavidG
Nov 12 '18 at 9:59














@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

– Adam Mitchell
Nov 12 '18 at 10:59





@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.

– Adam Mitchell
Nov 12 '18 at 10:59












3 Answers
3






active

oldest

votes


















2














You could use an f-string if you’re working in python 3.6+



This is the most efficient method.



counter = 0
filepath = f"/home/user/imagecounter.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))


Otherwise the second best would be using the .format() function:



counter = 0
filepath = "/home/user/image0.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))





share|improve this answer
































    1














    You can use Python's .format() method:



    counter = 0
    filepath = '/home/user/image0.jpeg'.format(counter)
    image = ClImage(file_obj=open(filepath, 'rb'))





    share|improve this answer






























      1














      You need string concatenation.



      >>>counter = 0;

      >>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))





      share|improve this answer































        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        You could use an f-string if you’re working in python 3.6+



        This is the most efficient method.



        counter = 0
        filepath = f"/home/user/imagecounter.jpeg"
        image = ClImage(file_obj=open(filepath, 'rb'))


        Otherwise the second best would be using the .format() function:



        counter = 0
        filepath = "/home/user/image0.jpeg".format(counter)
        image = ClImage(file_obj=open(filepath, 'rb'))





        share|improve this answer





























          2














          You could use an f-string if you’re working in python 3.6+



          This is the most efficient method.



          counter = 0
          filepath = f"/home/user/imagecounter.jpeg"
          image = ClImage(file_obj=open(filepath, 'rb'))


          Otherwise the second best would be using the .format() function:



          counter = 0
          filepath = "/home/user/image0.jpeg".format(counter)
          image = ClImage(file_obj=open(filepath, 'rb'))





          share|improve this answer



























            2












            2








            2







            You could use an f-string if you’re working in python 3.6+



            This is the most efficient method.



            counter = 0
            filepath = f"/home/user/imagecounter.jpeg"
            image = ClImage(file_obj=open(filepath, 'rb'))


            Otherwise the second best would be using the .format() function:



            counter = 0
            filepath = "/home/user/image0.jpeg".format(counter)
            image = ClImage(file_obj=open(filepath, 'rb'))





            share|improve this answer















            You could use an f-string if you’re working in python 3.6+



            This is the most efficient method.



            counter = 0
            filepath = f"/home/user/imagecounter.jpeg"
            image = ClImage(file_obj=open(filepath, 'rb'))


            Otherwise the second best would be using the .format() function:



            counter = 0
            filepath = "/home/user/image0.jpeg".format(counter)
            image = ClImage(file_obj=open(filepath, 'rb'))






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 '18 at 10:49

























            answered Nov 12 '18 at 10:44









            JabaJaba

            6,854175294




            6,854175294























                1














                You can use Python's .format() method:



                counter = 0
                filepath = '/home/user/image0.jpeg'.format(counter)
                image = ClImage(file_obj=open(filepath, 'rb'))





                share|improve this answer



























                  1














                  You can use Python's .format() method:



                  counter = 0
                  filepath = '/home/user/image0.jpeg'.format(counter)
                  image = ClImage(file_obj=open(filepath, 'rb'))





                  share|improve this answer

























                    1












                    1








                    1







                    You can use Python's .format() method:



                    counter = 0
                    filepath = '/home/user/image0.jpeg'.format(counter)
                    image = ClImage(file_obj=open(filepath, 'rb'))





                    share|improve this answer













                    You can use Python's .format() method:



                    counter = 0
                    filepath = '/home/user/image0.jpeg'.format(counter)
                    image = ClImage(file_obj=open(filepath, 'rb'))






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 '18 at 10:02









                    Adam MitchellAdam Mitchell

                    7581627




                    7581627





















                        1














                        You need string concatenation.



                        >>>counter = 0;

                        >>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))





                        share|improve this answer





























                          1














                          You need string concatenation.



                          >>>counter = 0;

                          >>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))





                          share|improve this answer



























                            1












                            1








                            1







                            You need string concatenation.



                            >>>counter = 0;

                            >>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))





                            share|improve this answer















                            You need string concatenation.



                            >>>counter = 0;

                            >>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 12 '18 at 10:06









                            Lie Ryan

                            44.6k968122




                            44.6k968122










                            answered Nov 12 '18 at 10:03









                            betontalpfabetontalpfa

                            8451023




                            8451023













                                Popular posts from this blog

                                Kleinkühnau

                                Makov (Slowakei)

                                Deutsches Schauspielhaus