OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python


> 
> *def get_fstype_of_mounted_partition(self, fs):*
>        """
>            Get the filesystem type of the mounted partition.
> 
>            :partition_name : Partition path as string (e.g. /dev/mmcblk0p1)
>            :return: filesystem type as string or None if not found
>        """
> 
> *        cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
>        *return self._helper.execute_cmd_output_string(cmd)*
> 
> 
> 
> root:~/qa/test_library# python3 sd.py
>  File "sd.py", line 99
> *    cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
> *         ^*
> *SyntaxError: can't assign to literal*
> root:~/qa/test_library#
> 

looking at
 cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*

It?s probably because you have ? characters that are inside ? characters and it can?t tell where the string ends. It looks like you are trying to do

cmd = "blkid -o export %s | grep 'TYPE' | cut -d?      =      " -f3" % (fs)*

which doesn?t make sense.  Try using triple quotes instead so it?s clear what string you are trying to use.

cmd = ?""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3?"" % (fs)


? 
David Rock
david at graniteweb.com